Intro
For styling the UI we make use of CSS. To get more functionality and structure out of the CSS we make use of SASS/SCSS.
In general, this is a diry language, if not maintained. It is up to the developers to keep it clean and documented.
Structure
Within the folder src/scss/
you can find the SCSS setup and how we create the styling for the brandplatform and its
styleguides. Each styleguide is represented by a folder and a file with the same name.
general:
The general styleguide, where the styling of components, layout and settings is located. If creating multiple stylguides
within the brandplatform, this can be seen as the basis. When creating a new styleguide, this structure must be inherited.
This folder and has a file that imports all the components and makes sure that all the styling can be used when linking
this file in the <head>
of your site: general.scss.
brandplatform
The styling related to the look and feel of the brandplatform itself. When delivering a stylguide, this should not be linked
within the <head>
tag. It is only useful for the brandplatform itself. Outside of the folder is a file called
brandplatform.scss which is used to import the components and create one CSS file.
_vendors
Folder containing third party or minified libraries used to create certain components like a carousel, to overwrite
this property a file must be placed within the corresponding styleguide vendors folder.
Styleguide
Standard there is one styleguide present in the brandplatform: general. If there is need to add more, a new folder carrying the name of the styleguide should be added into src/scss
. To make use of the components created within that folder a file containing
all the imports should be added as well, carrying the same name, but with the file extension .scss
. Each folder contains the same
structure to keep everything consistent and familiar:
components:
Contains all the atoms, molecules, organisms and quarks to create the different type of building blocks like a button or header
layout:
Contains the layout needed to create the pages like grid or container
settings:
Contains all the global variables used throughout each component like colors, typography or layout
tools:
Contains helper mixins, functions and extends to make our lives in the wonderfull world of SCSS easier and more enjoyable
utils:
Contains helper classes, not related to any UI, with one specifc role like creating spacing or hiding elements
vendors:
Contains styling used to overwrite third party libraries, this does not contain the minified files
scopes:
Is an optional folder that is likely not to be used within each brandplatform. These are not components, but represent a
scope used in a certain context. For example: when the HTML or parts of it gets generated by a third party like Mendix or other plugins. A scope can be defined to style regular HTML tags and overwrite classes.
_shame.scss:
Hacks or dity CSS, which is temporarliy and is only implemented to fix an unsolvable issue
Component
Each component is represented by one file: _button.scss, _grid.scss, ... . The styling of the initial component does not leave this
file. The structure within this file should be consistent and similar to each component file within the its folder. Each selector
should be nothing more than a simple class, selecting them through tags must only be done within the quarks folder in order to keep
the specificity low and avoid the use of !important.
Name of the component
Contains simply comments explaining what the component is and what it contains
Settings
Private or internal variables used within the component, each variable should have a clear name to what it does, comment is if its too complex.
Root
The B** or the **Block when using the BEM principle. In general it is the root of the component, containing the different children.
Elements
The E** or the **Elements when using the BEM principle. These are the children of the root of the component.
Modifiers
The M** or the **Modifiers when using the BEM principle. These are the adjustments or modified versions of the Block or Elements defined above.
States
These are the temporarily states defined on the Block, Elements or Modifiers. As stated before, these should always start with
is- or has-.
// ============================================================================
// :: Button
// ============================================================================
// ============================================================================
// :: Settings
// ============================================================================
// ============================================================================
// :: Root
// ============================================================================
.a-button {}
// ============================================================================
// :: Elements
// ============================================================================
.a-button__icon {}
// ============================================================================
// :: Modifiers
// ============================================================================
.a-button--dark {}
.a-button__icon--disabled {}
// ============================================================================
// :: States
// ============================================================================
.a-button {
&.is-active {}
&.has-icon {}
}
Sorting
A very important thing, that is just as difficult as naming a component is keeping the code consistent and familiar. This can be done
by sorting the CSS properties. Here we sort our properties based on type so that every developer know where the properties are located within a selector. Every group of properties should be seperated by an enter
.
Position
position: absolute;
top: 0;
left: 0;
z-index: 10;
display: flex;
justify-content: "space-between";
align-items: "center";
width: 10rem;
height: 10rem;
padding: 1rem;
margin: 1rem;
Text or font
font-family: "awesome";
font-size: $font-size-base;
font-weight: bold;
line-height: $line-height-2x-small;
letter-spacing: 1;
text-align: center;
text-transform: uppercase;
Decorators
color: yellow;
background-color: black;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.08);
border: 1px solid white;
background: url("awesome.png") no-repeat center;
opacity: 1;
Transforms
transform-origin: center;
transform:
translateX(10px)
translateY(10px)
scale(1)
rotate(10deg)
skewX(10deg)
skewY(10deg);
Animations
transition: opacity 0.3s ease-in-out;
animation: awesome 0.3s ease-in-out infinite alternate;
Other
cursor: pointer;
pointer-events: none;
list-style-type: none;
Specificity
This determines which CSS rule is applied by the browsers, based on how the selector is build up. When your CSS-rules don't apply,
this means that another selector has higher specificity and will be applied. Based on how one is build up, it is easy to overwrite one. This is the reason why we try to limit our selector by just one simple class. We also avoid the use of !important.
Specificity determines, which CSS rule is applied by the browsers. Specificity is usually the reason why your CSS-rules don't apply to some elements, although you think they should. Every selector has its place in the specificity hierarchy.27 jul. 2007
low specificity:
.a-button {}
.l-grid {}
.o-header {}
high specificty (avoid this):
.a-button > a:first-child {}
.o-header .o-header__content .m-list .m-list__item:first-child {}