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>
效果图:
本文通过一个具体的HTML示例介绍了CSS中使用!important声明来提高样式的优先级的方法。当样式冲突时,!important可以确保指定的样式被应用,即使是在内联样式存在的情况下。
429

被折叠的 条评论
为什么被折叠?



