我只想改變標題文本的顏色,我不知道爲什麼下面的代碼不起作用?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