Loading
Quick talk on writing efficient CSS Selectors, covering;
By process of elimination the browser parses CSS rules to locate targets.
Consider:
form#unique > div {}
Question: for the above rule what would the first set of elements consist of?
Answer: All of the div elements in the entire DOM.
Browsers read your CSS selectors from RIGHT to LEFT
Stylus, SASS, LESS, etc. are great productivity tools.
Consider LESS:
body{ table { &.class1 { } &.class2 { } } }
Compiled:
body table.class1{ } body table.class2{ }
Pre-processors can offer great structure, and maintainability. But what is wrong here in terms of performance?
Note: Selectors efficiency may not suite all use cases.
#unique
.reusable
tr
tr + th
div > p
div a
[type="email"]
:focus
Please don't go crazy and style ID's
Knowing that CSS selectors are read from RIGHT to LEFT we now consider;