[英]How to avoid child elements to get text-decoration style from body element's style
HTML example: HTML示例:
<span>line1</span>
<div id="div1" class="no-underline">
<div id="div2" class="no-underline">subline1</div>
<div>subline2</div>
</div>
body {
font-family: Arial;
font-size: 8px;
color: rgb(255, 0, 85);
font-weight: bold;
font-style: italic;
text-decoration: underline;
}
#div1 {
color: black !important;
}
#div2 {
color: green;
}
.no-underline {
text-decoration:none !important;
}
The result is : 结果是:
I want subline1 and subline2 not underlined. 我希望subline1和subline2不带下划线。 But body's style should stay at my case.
但是身体的风格应该由我来决定。
How is this possible? 这怎么可能?
First I would recommend to avoid using inline Css and !important, that's a bad practice and will make your code very hard to modify later. 首先,我建议避免使用内联Css和!important,这是一种不好的做法,并且会使以后的代码很难修改。 one solution would be to put your text decoration on the span:
一种解决方案是将文本修饰放在跨度上:
<span style ="text-decoration: underline;">
line1
</span>
Here you go! 干得好! http://jsfiddle.net/41ragvd2/
http://jsfiddle.net/41ragvd2/
<body style="font-family: Arial; font-size: 8px; color: rgb(255, 0, 85); font-weight: bold; font-style: italic;" >
<span style="text-decoration: underline;">
line1
</span>
<div style="color:black; !important;">
<div style="color:green; !important;">
subline1
</div>
<div>
subline2
</div
</div>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.