[英]How can I override inline styles on contained elements with CSS?
在以下代码段中,我想覆盖内联样式,以便h1
、 h2
、 h3
、 h4
标签具有写入 CSS 文件的样式。
h
标签本身或span
或任何其他子/嵌套元素。span
但span
可以是第 n 个孩子 .wrapper{} h1,h2,h3,h4 {line-height:1.5 !important;} h1,h2 > span {color:rgb(41,105,176) !important;} h3,h4 > span {color:rgb(184, 49, 47) !important;}
<div class="wrapper"> <h1>Dyspepsi</h1> <h2><span style="color: rgb(0,0,0);">Dyspepsi</span></h2> <h1><strong><em><span style="color: rgb(0,0,0); line-height:2.5">Dyspepsi</span></em></strong></h1> <h2><strong><em><span style="color: rgb(0,0,0);">Dyspepsi</span></em></strong></h2> <h3><strong><span style="color: rgb(0,0,0); border-bottom: 1px solid;">Dyspepsi</span></strong></h3> <h4><strong><em><span style="color: rgb(0,0,0);">Dyspepsi</span></em></strong></h4> </div>
除了常规的 h1 到 h4 选择器之外,您还可以将“all”选择器*
与标题选择器结合使用(作为子项),并在所有这些选择器上加上!important
:
h1, h1 *, h2, h2 *, h3, h3 *, h4, h4 * { line-height: 1.5 !important; } h1, h1 *, h2, h2 * { color: rgb(41, 105, 176) !important; } h3, h3 *, h4, h4 * { color: rgb(184, 49, 47) !important; }
<div class="wrapper"> <h1>Dyspepsi</h1> <h2><span style="color: rgb(0,0,0);">Dyspepsi</span></h2> <h1><strong><em><span style="color: rgb(0,0,0); line-height:2.5">Dyspepsi</span></em></strong></h1> <h2><strong><em><span style="color: rgb(0,0,0);">Dyspepsi</span></em></strong></h2> <h3><strong><span style="color: rgb(0,0,0); border-bottom: 1px solid;">Dyspepsi</span></strong></h3> <h4><strong><em><span style="color: rgb(0,0,0);">Dyspepsi</span></em></strong></h4> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.