由 Ghostzhang 发表于 2005-10-19 18:36
在CSS中,你可以为同一个标签定义多个样式,如下面的例子:
#aaa{
background-color: Fuchsia;
}
.ab{
background-color: Black;
}
td{
background-color: Aqua ;
}
<table>
<tr>
<td class="ab" id="aaa" style="height:200px;width:200px;background-color: Blue;"></td>
</tr>
</table>
这么多的样式,哪个是有效的呢? 我们一个一个把上面的样式删除,在浏览器中可以看到: style的优先级最高,然后是id,再来是class,最后才是td 另外,使用!important可以改变优先级别为最先,如下:
#aaa{
background-color: Fuchsia;
}
.ab{
background-color: Black;
}
td{
background-color: Aqua !important;
}
<table>
<tr>
<td class="ab" id="aaa" style="height:200px;width:200px;background-color: Blue;"></td>
</tr>
</table>
td将会显示为Aqua 即优先级变为td,然后是style,再来是id,最后是class
注:谢谢朋友指出了文章中的一个错误,现已经改正。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有