CSS 覆盖 inline style 样式

更新日期: 2020-03-12 阅读次数: 4430 字数: 73 分类: CSS

内联非 !important 样式

<div class="head_b" style="height: 52px; background-color: rgb(195, 195, 195);">

<style>
div[style] {
   background: yellow !important;
}
</style>

内联 !important 样式

由于内联 !important 样式不可覆盖,所以只能使用 js 替换的方式来解决。

<div class="head_b" style="height: 52px; background-color: rgb(195, 195, 195) !important;">

<script>
document.querySelector(".head_b").style.backgroundColor="#c3c3c3";
</script>

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式