!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样式-->

posted @ 2019-12-30 14:01  JAVA之家TY  阅读(346)  评论(0编辑  收藏  举报