An Interest In:
Web News this Week
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
12 CSS Best Practices by Twitter
When grouping selectors, keep individual selectors to a single line.
Lowercase all hex values and use shorthand hex values whenever possible.
Related property declarations should be grouped together following the order: position, box-model, typography, visual. misc.
Don't use
!important
- It is a last resort generally and only use when you need to override something and there is no other way. Instead increase the specificity of the selector.When a rule set includes only one declaration, consider removing line breaks for readability and faster editing.
Limit shorthand declaration usage to instances where you must explicitly set all available values.
Ensure your code is descriptive, well commented and approachable by others. Great code comments convey context and/or purpose.
Class names:
a. Keep them lowercase and use dashes to separate words
b. Avoid excessive shorthand notation. (.btn
is fine,.s
is not)
c. Use meaningful names: use structural or purposeful names over presentation.
d. Prefix classes based on the closest parent or base class.Selectors:
a. Use classes over generic element tag for optimum rendering performance.
b. Avoid using several attribute selectors (e.g.[class^="..."]
) on commonly occurring components. Browser performance is known to be impacted by these.
c. Keep selectors short and strive to limit the number of elements in each selector to three names over presentational.Place media queries as close to their relevant rule sets whenever possible.
...
Original Link: https://dev.to/pritampatil/12-css-best-practices-by-twitter-2fap
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To