I have markup that uses inline styles, but I don't have access to change this markup. How do I override inline styles in a document using only CSS? I don't want to use jQuery or JavaScript.
HTML:
<div style="font-size: 18px; color: red;">
Hello World, How Can I Change The Color To Blue?
</div>
CSS:
div {
color: blue;
/* This Isn't Working */
}
inline-styles
in a document have the highest priority, so for example say if you want to change the color of adiv
element toblue
, but you've aninline style
with acolor
property set tored
So, Should I Use jQuery/Javascript? - Answer Is NO
We can use
element-attr
CSS Selector with!important
, note,!important
is important here, else it won't over ride the inline styles..Demo
Below is the link for more details: http://css-tricks.com/override-inline-styles-with-css/
To only way to override inline style is by using
!important
keyword beside the CSS rule. Following is an example of it.You can easily override inline style except inline
!important
styleso
but if you have
now it will be
red
only .. and you can not override it