如何重写!重要的内联css?

时间:2021-10-14 08:44:37

I'm editing a page and I can't change the html, only the css, but I need to change a background-image that is declared inline with !important. I've already tried to declare background-image: none !important; or change bg position until it disappear and then declare the new bg image on :before pseudo-element, but it doesn't work. Is there any way to do this WITHOUT change the html? Here's the code:

我正在编辑一个页面,我不能改变html,只有css,但是我需要改变一个被声明为内联的背景图片!我已经试图声明背景图像:没有!或者改变bg的位置,直到它消失,然后声明新的bg图像:在伪元素之前,但它不起作用。有没有什么方法可以在不改变html的情况下做到这一点?这是代码:

<ul class="list-inline">
    <li>
       <a href="http://www.facebook.com/portoseguro" target="_blank">
         <span class="gIconSocial fb" style="background: url('https://cliente.portoseguro.com.br/static-files/Institucional/Icones/facebook_off.png') no-repeat !important;">Facebook</span>
        </a>
    </li>
</ul>

(I can't use javascript too, only css)

(我也不能使用javascript,只有css)

2 个解决方案

#1


1  

You can hide the background image by adding the CSS background-size: 0; and try to put a background image to ul.list-inline > li > a[target=_blank]

您可以通过添加CSS背景大小:0来隐藏背景图像;并尝试将背景图像添加到ul。list-inline > li > a[target=_blank]

EDIT :

rather use ul.list-inline > li > a[target] or it wont work

而使用ul。list-inline > li > [target]或它不工作。

#2


2  

The browser gives the priority to the inline style. And, since this is with !important property you have to edit the HTML to get rid of this if you wanna do this with CSS only.

浏览器优先考虑内联样式。而且,因为这是和!重要的属性,你必须编辑HTML来摆脱这个如果你想用CSS来做这个。

I recommend you to read more about Specificity on applying styles

我建议你阅读更多关于应用风格的专一性。

#1


1  

You can hide the background image by adding the CSS background-size: 0; and try to put a background image to ul.list-inline > li > a[target=_blank]

您可以通过添加CSS背景大小:0来隐藏背景图像;并尝试将背景图像添加到ul。list-inline > li > a[target=_blank]

EDIT :

rather use ul.list-inline > li > a[target] or it wont work

而使用ul。list-inline > li > [target]或它不工作。

#2


2  

The browser gives the priority to the inline style. And, since this is with !important property you have to edit the HTML to get rid of this if you wanna do this with CSS only.

浏览器优先考虑内联样式。而且,因为这是和!重要的属性,你必须编辑HTML来摆脱这个如果你想用CSS来做这个。

I recommend you to read more about Specificity on applying styles

我建议你阅读更多关于应用风格的专一性。