Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts

    Multiple classes for a single element?

    Why have I not come across this before?
    Are there support problems, display inconsistencies, or some other issues?
    I was just dissecting Stu Nicholls' ProDroplineDropdown CSS Menu, and came across his use of 2 classes (seperated by a space) for certain elements.

    This was definitely a HOLY COW! moment, especially since I was just wishing for this yesterday.

    Are there any reasons to NOT do this?
    What is the limit on how many classes you can assign to a single element (for curiosity sake)?

    ~ Mo

  • #2
    Regular Coder
    Join Date
    Oct 2008
    Posts
    130
    Thanks
    0
    Thanked 4 Times in 4 Posts
    You read it just right. You can have as many classes as you want, which makes .class more flexible than #id. You can only have 1 id per element, however. I'm not saying, though, id is bad to use. You should use classes and ids for certain uses.

  • #3
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    ... You can only have 1 id per element...
    My understanding was that you are also limited to 1 instance of any ID for an entire page. Am I at least accurate with that?

    ~ Mo

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Yes, IDs are allowed once per page. Classes are reusable, so multiple elements can have the same class, and elements can have multiple classes.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    I seem to remember older versions of IE having issues with:
    Code:
    .class1.class2.class3.blablabla {
    /* properties */
    }
    But that is the only issue that can crop up with multiple classes (that is, selecting elements specifically having multiple classes).

  • #6
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Now I've got a cool new tool

    ~ Mo

  • #7
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Using multiple CSS classes on a HTML element is fine. You can't have more than one ID per page. But when you implement CSS class chaining you have to think to yourself - is what I am doing worth this much effort? Or could I simply use an ID instead and bundle all of the code into the ID selector instead.

    Don't just use classes because you can.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •