Is it improper to use an ID as a CSS selector? -
this question has answer here:
so use website liveweave.com test html, css, , javascript code i've written. has syntax checker, , whenever use id selector in css section, says improper use id selector.
i have demonstrated in this weaver. right of line 3 in css window yellow icon, which, when hovered over, says improper use ids selector. under impression that purpose of being used selector single dom element, opposed classes, designed applied multiple dom elements.
am wrong? improper use id selector?
the other instance can think of id being used javascript document.getelementbyid()
, , similar functions. proper use of id? note not asking difference between id , class, rather whether proper use id selector.
using id efficient way of selecting dom node in both css , javascript. use classes repeated items , ids unique items, or unique configurations of repeated modules. there many css patterns, use style called bem (block, element, modifier seen here) class based naming convention. @ favorite websites, right click or inspect. find there no 1 right answer question, many right answers.
may both exist in standard reason , serve purpose depending on applications needs.
below order of efficiency selectors. ids efficient , pseudo classes , pseudo elements least efficient.
id (#myid) class (.myclass) tag (div, h1, p) adjacent sibling (h1 + p) child (ul > li) descendent (li a) universal (*) attribute (a[rel=”external”]) pseudo-class , pseudo element (a:hover, li:first)
see here...
Comments
Post a Comment