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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:39:09  来源:igfitidea点击:

CSS class - H2 style not showing

css

提问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.spielboxmatches h2elements with the class spielbox
  • .spielbox h2matches h2elements that are within any element with the class spielbox
  • h2.spielboxh2元素与类匹配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>