CSS class – H2 style not showing

css

I've got this in my .css file:

h2.spielbox {
    margin-bottom:80px;
    color:#f00;
}

a.spielbox {
    text-decoration:none;
    background-color:#aff;
}

But in my html file the h2 style is not showing, while the a-style works:

<div class="spielbox" style="float:left;width:320px"><h2>Testberichte</h2>

Seems i am not knowing something about CSS ?

Best Solution

It's because you have the class applied to a div. Do this instead:

<h2 class="spielbox">Testberichte</h2>

Alternately, you can do this if you want to leave it in the div:

.spielbox h2 {
    margin-bottom:80px;
    color:#f00;
}
  • h2.spielbox matches h2 elements with the class spielbox
  • .spielbox h2 matches h2 elements that are within any element with the class spielbox