resource / Front-End-Standards

Front-end development standards for Resource.
MIT License
23 stars 1 forks source link

Why avoid use of #IDs? #54

Closed nicetransition closed 11 years ago

nicetransition commented 11 years ago

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.

lkrids commented 11 years ago

What is a good use case for ids in css?

nicetransition commented 11 years ago

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.

nicetransition commented 11 years ago

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.

LukeAskew commented 11 years ago

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.

LukeAskew commented 11 years ago

Didn't mean to close (hit the wrong button). Let's keep this conversation going.

nicetransition commented 11 years ago

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.

LukeAskew commented 11 years ago

I have closed for now. If this conversation needs to be revived, anyone is free to reopen.

nicetransition commented 11 years ago

Sounds good