How to Override Inline Styles with Style Sheet
Blog » CSS/XHTML » How to Override Inline Styles with Style SheetHow to Override Inline Styles with Style Sheet
There have been a few incidents when I came across wanting to override some inline styles and I always thought this was an impossible thing to do. The other day I stumbled across this article by Natalie Jost, and she actually came across some similar scenarios and came up with a very clever solution.
For example, lets say the html looked like this:
<div class="block"> <span style="font-weight: bold; color: red;">Hello World</span> </div>
You can override the child span by using the following css:
.block span[style]{
font-weight: normal !important;
color: #000 !important;
}
Unfortunately the down side of this is technique is that it will not work on IE6 and below, but it does work in IE7, IE8, Fire Fox, Safari, and Opera.
For more detailed explanation of this technique please check out Natalie Jost’s Article.
Similar Posts:
Tags: css, Dreamweaver, inline styles, Tutorial
This entry was posted on Tuesday, September 16th, 2008 at 9:03 pm and is filed under CSS/XHTML. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.






ah Thanks, this works well.
Hi guy,
I think you missed something in your code.
Back to “!important” mark, it will ensure that properties has it will be apply regardless any same one is set inline.
So, I have new code
.block span {
font-weight: normal !important;
color: #000 !important;
}
and it works well on any browser.
@Le Bao Phuc,
IE6 doen't support the !important mark. Search for "!important" at http://msdn.microsoft.com/en-us/library/cc351024(VS.85).aspx
The !important mark is the only way I know to override inline CSS.
So, for IE6 and below, we can do:
<!–[if lte IE 6]>
<script>…<script>
<![endif]–>
and pray for a ID attribute on that tag with inline css.
hi,
Thank you very much. share this CSS tips
hi soh,
can you help me it’s not work in IE-7
Hai Soh,
Plz plz plz help me it’s not working in IE7
superb…………ill try and ask u question…….bye
Thanks man!
thanks for that tip
Need one that works in Google Chrome