CSS !important 的使用

CSS的原理:
我们知道,CSS写在不同的地方有不同的优先级, .css文件中的定义小于元素style中的属性,但是如果使用!important,事情就会变得不一样。

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>!important</title>
<style>
.thisClass{ background-color:#f60 !important; font-weight:bold !important;}
</style>
</head>
<body>
<div class="thisClass" style="background-color:#06f; font-weight:normal;">阅谁问君诵,水落清香浮。</div>
</body>
</html>

效果图:

 

猜你喜欢

转载自onestopweb.iteye.com/blog/2314203
今日推荐