简体   繁体   English

覆盖通过JS使用CSS添加的内联样式

[英]Override Inline Styles added via JS with CSS

A js plugin is adding a style that is giving me some headache: 一个js插件正在添加一种令我头疼的风格:

element.style {
     z-index: 100 !important;
}

So i have tried this: 所以我试过这个:

html body div#shell div#shellContent div#bottomPart div#rightCol div.containerBox    
div#embedContainer div#janrainEngageEmbed div.janrainContent div#janrainView   
div.janrainHeader[style] {
    z-index: 1 !important;
}

and still nothing. 但仍然没有。

Contrary to the other answers, it is possible to override inline styles with CSS: 与其他答案相反,可以使用CSS覆盖内联样式:

http://css-tricks.com/override-inline-styles-with-css/ http://css-tricks.com/override-inline-styles-with-css/

I would guess that the extremely long selector might not be hitting the element. 我猜想极长的选择器可能没有击中元素。

I had a similar z-index issue with the Janrain plugin that was solved by this: 我有一个与Janrain插件类似的z-index问题,由此解决了:

#janrainEngageEmbed > div[style] {
    z-index: 0;
}

In your case, you probably need: 在您的情况下,您可能需要:

    z-index: 0 !important;

The inline style will trump any selectors. 内联样式将胜过任何选择者。 Either reset the style yourself in javascript or patch the plugin... it doesn't sound like a particularly well written anyway, to be honest. 要么自己在javascript中重置样式,要么修补插件......说实话,听起来并不是特别好。 : ) :)

inline style always override external and internal css, plus the fact that the plugin is using the !important clause (very bad practice!), all together makes it impossible to get it fixed with css only. 内联样式总是覆盖外部和内部css,加上插件使用!important子句(非常糟糕的练习!),所有这些都使得无法仅使用css修复它。 I reckon you will have to use some custom js to override the plugin settings. 我估计你将不得不使用一些自定义的j来覆盖插件设置。

maybe the best way would be to check if you can specify a callback function with the plugin and set the style as you wanted. 也许最好的方法是检查是否可以使用插件指定回调函数并根据需要设置样式。 another answer here suggested to edit the plugin itself, that is cool if you don't plan to ever update it - otherwise you're better off leaving the plugin code as it is, and just adding some bespoke js of your own 另一个答案在这里建议编辑插件本身,如果你不打算更新它,这很酷 - 否则你最好不要保留插件代码,只需添加一些你自己的定制js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM