簡體   English   中英

CSS-如何使用CSS覆蓋?

[英]CSS - how to overwrite using 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,為什么?

您需要刪除類定義之間的空格:

.mytitle.alt

簡單刪除.mytitle

.alt{  color: red;}       
.alt2{ color: black;}   

您將獲得所有alt / alt2顏色,或

.mytitle.alt{ color: red; }       
.mytitle.alt2{ color: black;}  

為兩者在一起。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM