!important在样式中的作用

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>!important</title>
</head>
<style type="text/css">
#test p{
color: #000 !important;
}
.fontstyle{
color:#00FF00;
}
</style>
<body>
<div id="test">
<p class="fontstyle">样式带有!important的元素优先级最高</p>
</div>
</body>
</html>
<!--#test p的color样式使用了!important ,所以有优先级最高,覆盖掉fontstyle样式-->

猜你喜欢

转载自www.cnblogs.com/java-ty/p/12119402.html