• Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

CSS - id and class

Eon-Rider

An "Original" PC Supporter
  • 7,498
    Posts
    20
    Years
    Erm... Lately I've noticed a lot of websites using id instead of class even when class is far more suitable.

    id can only be used once within a document.
    class can be used multiple times.

    Anyone care to explain why hardly anyone uses classes anymore?
     
    Rodaru said:
    class sucks, and if it only can be used once, how come my site's layout is using id more then once?

    Looking at your site you do not use the same id more than once.

    When he said "can only be used once within a document." He meant that you can not use the same ID twice. ( IE you can only use an id called "1" once. )
    Whereas with class you can use the same one multiple times. And therefore is better.

    Though, I generally use id because it's shorter than class, most of the time I change it when I'm done, but sometimes I do not.
     
    Uhh... "class sucks"? What the hell? Justify that, please. I dare you.

    Anyway, I don't see why people wouldn't use class. =/ I've always done it as it's supposed to, at the very least (and in fact, I sometimes use class for things that there is only one of if that is more appropriate semantically).
     
    class sucks, and if it only can be used once, how come my site's layout is using id more then once?

    It does still work but the w3 CSS Validator gives several errors about that.
     
    id is better used for a section of the site that will only exist once. That way you're giving it a firm "ID" that can't be used again.
     
    Back
    Top