How to put to classes in same css

Discussion in 'CSS' started by fadetoblack22, Jun 4, 2009.

  1. #1
    In my css file I have.

    .class1 {}

    .class2 {}

    If they both have similar code, is the correct way to group them like this:

    .class1 .class2 {}

    or

    .class1, .class2 {}

    thanks.
     
    fadetoblack22, Jun 4, 2009 IP
  2. qazu

    qazu Well-Known Member

    Messages:
    1,834
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #2
    .class1, .class2 {} is correct. It will assign the styles to both class1 and class2.

    .class1 .class2 {} would work only if class2 is a child of class1 but it assigns the styles to class2 and not class1.
     
    qazu, Jun 5, 2009 IP
  3. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #3
    thanks, that helps. I had it the incorrect way in my css.
     
    fadetoblack22, Jun 6, 2009 IP
  4. morg

    morg Peon

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes, qazu is right, that's the cascading effect of CSS
    I suggest CSS: The Missing Manual
     
    morg, Jun 14, 2009 IP