- [LAYOUT] - Don't forget about semantics, div development is not a better option
- [STYLES] - Get used to style all elements using classes. And don't increase selectors specificity unless completely necessary.
- [STYLES] - If you need to adjust positioning with
1px
or fractional numbers like0.5
, you are doing something wrong, change the alignment technique you use - [STYLES] - Be consistent with your margins - if you have many sections in a row, add margins either to the bottom or to the top so that it will be easier to identify how to position the next element
- [BEM] - Check your BEM structure using BEM-linter (
npm run lint
) and this list - [BEM] - create a separate file per each BEM block styles that have the same name as the block
- [BEM] - Make sure to follow BEM naming convention
GOOD example:
<div class="product__rating">
<div class="product__stars stars stars--4">
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
<div class="stars__star"></div>
</div>
</div>
BAD example:
<div class="product__rating">
<div class="product__stars stars--4">
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
</div>
</div>
`stars--4` is a modifier of the `stars` block, but `stars` block does not exist in HTML;
`star` is another block, stars should be the elements of the `stars` block
- [BEM & STYLES] - Don't add external styles (positioning or margins) to BEM-blocks. Use mix where necessary and move all external styles under element selector.
GOOD example
<!--index.html-->
<div class="container">
<div class="container__card card">
...
</div>
</div>
/*style.css*/
.container__card {
margin: 48px 24px;
}
.card {
font-size: 16px;
background-color: purple;
}
BAD example
<!--index.html-->
<div class="container">
<div class="card">
...
</div>
</div>
/*style.css*/
.card {
margin: 48px 24px;
font-size: 16px;
background-color: purple;
}
- [SASS] - Make use of SASS nesting - write pseudo-class, pseudo-element selectors inside general selector. As well as media queries.
GOOD example:
&__buy-link {
display: flex;
margin-top: 20px;
&:hover {
color: blue;
}
}
BAD example:
&__buy-link {
display: flex;
margin-top: 20px;
}
&__buy-link:hover {
color: blue;
}
- [SASS] - use variables for the main values so that you'll be able to reuse them and give them descriptive names. But don't overuse them, don't create variable for the value that's used just once.
- [SASS] - Try to use different features - mixins etc - where it makes sense.
- [CODE STYLE] - Remember about styles properties order - (css order)