Thursday, April 28, 2011

Overriding inline CSS styles in IE7

I have a html tag with inline CSS style like: <body><div style="position:absolute;top:100px;"></body> and I want to override this inline position property. So, I wrote a CSS rule like this:

body > div[style]{position:relative !important;top:0px !important;}

The above code works in Firefox. But in IE7 it does not work. Am I missing anything for IE?

PS: Even though I could see my overridden attributes in Firebug lite window, it's not affecting anything on my page. (Plz refer the attached image).

alt text

From stackoverflow
  • Your selector doesn't need to be that specific - I'm not sure but I'm not sure IE7 would understand it. The !important should override it.

    Have you tried this?

    body div {position:relative !important;top:0px !important;}
    
    Veera : yeah.. if i changed like this, it works. :)
  • The style attribute selector is not supported in IE7: http://reference.sitepoint.com/css/css3attributeselectors

    derekerdmann : This isn't a CSS3 attribute selector. All it does is match any elements that have `style` defined. http://reference.sitepoint.com/css/attributeselector
    Will Prescott : Sure, I was only referring to the compatibility section of that page which suggests that style cannot be used in any attribute selectors in IE7 (CSS3 or otherwise), which having tested it seems to be true.

0 comments:

Post a Comment