3 ms·
why is disallowing id's a feature? it makes headless testing so much more easier, amongst other things.
by minusf 6y ago
why is disallowing id's a feature? it makes headless testing so much more easier, amongst other things.
- AltruisticGapHN 6y agoIds overpower everything else in the css cascade, in particular any utilities like tailwind’s (unless you activate !important for utils, which also has its cascading effects and heavyhanded fix). Using an id is not inherently wrong, and with stylelint you can always disable a rule for the exceptions, with a comment of the form /* stylelint-disable-next-line <optional specific rule id> */ Nowadays esp. with composition methodology it’s almost always better to just use a unique bem like class, eg. .HomepageHero-carousel , even if the element in question is a "singleton"... because later someone can stick a mb-4 on it, or a text-lg , or even your own custom utility or modifier and it will stick, without snowballing css selector complexity.
- AltruisticGapHN 6y agoI didn’t understand your reply at first. If you use ids for easy targeting parts of html, then it doesn’t matter, stylelint doesn’t check the html. Applying styles can be done via classes so the css selectors in your stylesheets do not need to mention any #ids. Applying styles with #ids however, is an issue.