我只想改变标题文本的颜色,我不知道为什么下面的代码不起作用?CSS - 如何覆盖使用CSS?
<div class="mytitle">
this is the title in white
</div>
<div class="mytitle alt">
this is the title in red
</div>
<div class="mytitle alt2">
this is the title in black
</div>
.mytitle{
font-family: Verdana, Geneva, sans-serif;
font-size: 37px !important;
line-height: 40px !important;
display:block;
font-weight: bold;
margin: 0 0 12px;
padding: 0 15px 5px 0 !important;
color: white;
width:500px;
}
.mytitle .alt{
color: red;
}
.mytitle .alt2{
color: black;
}
编辑:它只会使用“mytitle”标记,它不会使用alt或alt2,为什么?
这是我的错别字,实际的CSS有一个空间。 – 001 2011-05-07 14:46:37
001,*删除*空格。 .mytitle .alt(带空格)适用于.alt INSIDE .mytitle,而.mytitle.alt(不含空格)适用于具有这两个类的元素。 – 2011-05-07 14:48:43
@ 001当我修复它时,它适用于我:http://jsfiddle.net/Q77pF/ – 2011-05-07 14:49:03