I read some where that its better to use less specific selectors in CSS. I’m on my second FCC project (the survey form), and see that they asked for elements to be tagged with id="".
Is there a reason for the projects requests for ID tags? What is the reason for using class tags over id tags?
By the way, I’m a week old newbie to coding =)
The introductory course to HTML5 does use classes. In the certification projects, it’s easier for the tests to target ids, since they’re unique, whereas a class can legitimately be used by multiple elements. Telling students to only use a class on one particular element would run counter to the intended use of classes.
Thanks @jenovs. The article was helpful. It makes sense to keep more specific selectors towards the end of the CSS in order to avoid redefining properties. I say this but truthfully I do not fully understand this because I do not have enough experience. Nevertheless, I now know better working habits to strive for.
@chuckadams, that makes sense. So, you’d only want to tag selectors as classes when they actually belong to a… group.
It’s perfectly legit for a class to only get applied to a single element, and indeed it happens all the time. It’s just that they can potentially be repeated, and that would make the tests much more complicated to sort out which element they’re actually supposed to be testing.
In the real world, you’re likely to use a combination of both ids and classes, since you might also write acceptance tests similar to FCC’s to ensure certain elements are present.