CSS 类 - H2 样式未显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6169618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS class - H2 style not showing
提问by Karl H.
I've got this in my .css file:
我的 .css 文件中有这个:
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:
但是在我的 html 文件中,h2 样式没有显示,而 a 样式有效:
<div class="spielbox" style="float:left;width:320px"><h2>Testberichte</h2>
Seems i am not knowing something about CSS ?
似乎我对 CSS 一无所知?
回答by Wesley Murch
It's because you have the class applied to a div
. Do this instead:
这是因为您将该类应用于div
. 改为这样做:
<h2 class="spielbox">Testberichte</h2>
Alternately, you can do this if you want to leave it in the div:
或者,如果你想把它留在 div 中,你可以这样做:
.spielbox h2 {
margin-bottom:80px;
color:#f00;
}
h2.spielbox
matchesh2
elements with the classspielbox
.spielbox h2
matchesh2
elements that are within any element with the classspielbox
h2.spielbox
将h2
元素与类匹配spielbox
.spielbox h2
匹配h2
具有该类的任何元素内的元素spielbox
回答by Kamil
you have set the spielbox class for h2, so you need to type it in h2,
你已经为 h2 设置了 spielbox 类,所以你需要在 h2 中输入它,
<h2 class="spielbox">...</h2>