Closed nicetransition closed 11 years ago
What is a good use case for ids in css?
To identify non-repeatable structure elements (such as a #header
, #main
, #footer
). ID's are faster than classes and for items such as global non-repeatable elements they are good use.
I think ID fall under element-selectors, they should be more of a normalize and not include styles just structure. The focus should be for optimizing these selectors for JS usage though.
It is a dangerous to assume any element will not be repeatable. IDs also throw off any specificity patterns you're trying to bake into your stylesheet.
I don't think IDs are much faster than classes in CSS. They are slightly faster as DOM selectors in older browsers that don't support querySelectorAll. The best use case for IDs is when binding events in older browsers. IMO.
Didn't mean to close (hit the wrong button). Let's keep this conversation going.
I'm cool with it, but I have been following this:
ID for global master-template-elements that are non-repeatable and applying only structure (not skin) to them. Then adding classes for styling or using @extend
in SASS.
If this is a rule, we should include a piece on "when/why to use ID" for JavaScript purposes.
I have closed for now. If this conversation needs to be revived, anyone is free to reopen.
Sounds good
This isn't a standard but more of language usage. There is a time and place to use ID but saying "Avoid use of #IDs" is harsh -- if this is included it should be explained when to use @id and when not to.