简体   繁体   中英

CSS - how to overwrite using CSS?

I only want to change the colour for the title text, I dont know why the following code does not work?

<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;
}

EDIT: it would only use "mytitle" tag, it would not use alt or alt2, why?

您需要删除类定义之间的空格:

.mytitle.alt

simple remove .mytitle

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

and you will get all alt/alt2 colored, or

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

for the both together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM