样式已存在的样式(如何过度骑行)

时间:2013-09-29 23:56:15

标签: css css-selectors

我有一个建立在CMS上的网站。自定义页面生成的html中添加了样式,而不是样式表。

我需要删除class .page_text的任何div下的span元素的background-color属性,或者将其更改为none。

为丑陋的html块道歉:

<div class="page_text">
  <h2 dir="ltr" style="line-height: 1.15; margin-top: 10pt; margin-bottom: 2pt;">
     <span style="font-weight: normal;">
       <p dir="ltr" style="line-height: 1.15; margin-top: 0pt; margin-bottom: 0pt; display: inline !important;">
     <span style="font-size: 15px; font-family: Arial; color: rgb(51, 51, 51); background-color: rgb(255, 255, 255); vertical-align: baseline; white-space: pre-wrap;">If you’d like to contribute to Trashswag you can submit “reports” in several ways.</span></p></span><br></h2>

我需要删除background-color属性。使用Chromes检查元素功能,沿

行选择

.page_text h2 span {background-color: none;}应该有效。它没有。

有人能指出如何选择.page_text中的所有范围吗?

2 个答案:

答案 0 :(得分:3)

您的尝试有两个问题。

正如@Tigran Petrossian所提到的,由于内联样式,您需要使用!important。但是,您还需要使用transparent代替none(这是background-color的无效值)。

这将有效:

.page_text h2 span {
    background-color: transparent !important;
}

(您可以改为使用background: none !important,因为隐式将background-color设置为transparent的初始值。More info.

答案 1 :(得分:2)

内联样式始终为a higher specificity,因此您必须使用!important

.page_text h2 span {background-color: none !important;}