繁体   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