Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS CSS Class and Id

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #240330
    vgoda
    Participant

    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.

    #240331
    Atelierbram
    Participant

    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.

    #240461
    vgoda
    Participant

    Thank you for the reply. Iam new to CSS. Why did the ids declared for the elements in HTML not in the CSS file?

    #240463
    Beverleyh
    Participant

    Please see Atelierbram’s answer – most likely because the ids are being used in JS or as anchors for links.

    #240535
    vgoda
    Participant

    Thanks Atelierbram and Beverleyh.

    #240654
    I.m.learning
    Participant

    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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘CSS’ is closed to new topics and replies.