How to Override Inline Styles with Style Sheet

Blog » CSS/XHTML » How to Override Inline Styles with Style Sheet

How to Override Inline Styles with Style Sheet

PrintSeptember 16th, 2008

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.

Bookmark or Share this Post!
Digg del.icio.us StumbleUpon Technorati TwitThis E-mail this story to a friend!

Tags: , , ,

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.

Speak Your Mind…

Need to post HTML code?
Use Postable for your convenience.

Don't have an Avatar?
Set up a Gravatar image now!

Blog Blog Categories

Popular Comments Popular Posts

Recent Comments Recent Comments