- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
All,
I was looking at a website. When i looked at the source HTML i see class and id defined for the HTML elements. But when i opened the CSS file i only see classes from the HTML and not the ids defined. Anyone know why both class and id are in HTML and only classes are defined in the CSS?
Thanks.
Reasons why it is common practice now to use mainly classes in CSS is the extremely high specificity of ID’s, which makes it harder to override declarations set before. ID’s are also unique, and classes are not, so this makes classes more versatile, also because there can be multiple classes on one element in HTML.
ID’s can be convenient for targeting elements in javaScript, and as targets for anchor-links.
Thank you for the reply. Iam new to CSS. Why did the ids declared for the elements in HTML not in the CSS file?
Please see Atelierbram’s answer – most likely because the ids are being used in JS or as anchors for links.
Thanks Atelierbram and Beverleyh.
I had a similar issue with my buttons; in order to style these, ID’s did not format but the classes had the ability. I spent several hours trying to make the ID style, but failed. As I read these replies, I may have had to use !important to override the presets (I used Bootstrap base code), but figured with the issues I have with my host’s server adding its own code, I gave up.