通过!important设置css样式优先级

CSS写在不同的地方有不同的优先级,一般 .css文件中的定义 < 元素style中的属性,但是如果使用!important,则会变得不一样,使用!important的css定义是拥有最高的优先级的

//html
<div class="testClass" >
        Important优先级
</div>

//css
.testClass{ 
color:blue !important;
}

以上,在div上面设置了颜色为红色的内联样式,此时的优先级最高,但如果想要将字体颜色设置为蓝色 ,则需要添加!important 像这样:

.testClass{

color:blue !important;

}