CSS 覆盖 inline style 样式

发布时间: 2020-03-12 15:33:29 作者: 大象笔记

内联非 !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>
我是一名山东烟台的开发者,联系作者