Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override Inline Styles added via JS with CSS

A js plugin is adding a style that is giving me some headache:

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.

like image 751
Jamie Hutber Avatar asked Jul 01 '12 11:07

Jamie Hutber


People also ask

Can you override inline style with CSS?

The only way to override inline style is by using ! important keyword beside the CSS rule.

How do you override a style in CSS?

To override the CSS properties of a class using another class, we can use the ! important directive. In CSS, ! important means “this is important”, and the property:value pair that has this directive is always applied even if the other element has higher specificity.

How do you override inline CSS without important?

The only way to override a CSS rule without using ! important is to use a more specific selector. No selector is more specific than the style attribute. Save this answer.


2 Answers

Contrary to the other answers, it is possible to 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:

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

In your case, you probably need:

    z-index: 0 !important;
like image 179
Jeff Clemens Avatar answered Sep 20 '22 21:09

Jeff Clemens


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. : )

like image 45
John Green Avatar answered Sep 18 '22 21:09

John Green