CSS教程:标签的class属性,指定多个样式时,优先级顺序

案例

下面代码:

css:

<style type="text/css">
.c1 {color:blue;}

.c2 {color:green;}
</style>

html:

<h1 class="c1 c2">class先c1,再c2</h1>
<h1 class="c2 c1">class先c2,再c1</h1>

执行结果:都显示的为绿色

优先级

class 属性中样式的顺序无关

c1c2定义顺序有关,定义在后面的优先级高

让文字显示为蓝色

css:

<style type="text/css">

.c2 {color:green;}
# 蓝色定义在后面,优先级高
.c1 {color:blue;}
</style>

html:

<h1 class="c1 c2">class先c1,再c2</h1>
<h1 class="c2 c1">class先c2,再c1</h1>

执行结果:都显示的为绿色

参考:
https://blog.csdn.net/qq_38719039/article/details/81511153


原文出处:https://malaoshi.top/show_1IX5T0PnVTeY.html