2

I have the following HTML:

<div class="block-content no-title grey-bg">

How can I set the background of this div to the color to #333?

Is there some kind of CSS selector that I can use to select just those block-content divs that have grey-bg?

  • 1
    Possible Duplicate: **[CSS Selector that applies to elements with two classes](http://stackoverflow.com/questions/3772290/css-selector-that-applies-to-elements-with-two-classes)** – Siva Charan Dec 31 '12 at 14:18
  • Refer the **[documentation](http://www.w3.org/TR/CSS2/selector.html#class-html)** for more details – Siva Charan Dec 31 '12 at 14:19

2 Answers2

9

There is something strange about your question.
This:

How can I set the background of this div to the color to #333?

Indicates you want this selector: [.grey-bg][.no-title][.block-content] (use one or more of the parts in square brackets).
This:

Is there some kind of CSS selector that I can use to select just those block-content divs that have grey-bg?

indicates you want this: .grey-bg.block-content.

11684
  • 7,356
  • 12
  • 48
  • 71
1

in css the space (or lack thereof) between selectors indicates either descendant or same dom object i.e.

<span class="a b">
    <span class="c"></span>
    <span class="b"></span>
</span>

//some css selector examples

.a.b{} //gets the first span (get all elements which have class .a and .b)
.a .b{} //gets the third (nested in a.b after .c - get all .b that are descendants of .a)
.b{}   //gets the first and third (get all .b)
.b>.b{} //gets the third (get all direct descendants of .b which are .b)
.b>.c+.b{} //gets the third (next sibling .b of a .c which is direct descendant of a .b)
Paul Sullivan
  • 2,865
  • 2
  • 19
  • 25