jBoive
jBoive

Reputation: 1299

CSS attribute selector in IE7 Standards mode

To make a long story short: I need to override display:none!important on some elements that have display:inline set inline on the HTML element itself.

This needs to work in IE with IE7 standards mode set.

Have a look at my pastebin link for details: http://pastebin.com/m06YXwHq Result: http://cdpn.io/sgrjz

This works in IE9 with IE9 Standards Mode (and all other modern browsers too), but no with IE7 Standards Mode.

Any help appreciated!

Upvotes: 0

Views: 132

Answers (2)

jBoive
jBoive

Reputation: 1299

As I stated, IE7 is unable to use the style-attribute as CSS selector.

I managed to work around it, so I'm out of the woods. No solution anyone else would find a use for as it's particular to my setup.

Thanks for all the input anyway!

/J

Upvotes: 0

Spudley
Spudley

Reputation: 168685

I honestly can't see a way to do what you want in pure CSS, other than fixing up your code to remove the mountains of bad practice that have led you down this path in the first place.

As you presumably already know, IE7 does not support attribute selectors used in this way so you're scuppered on that front, and the only other viable solution is to add a class to the element and style that (but if you could do that, I imagine you'd already have done it).

Beyond that, you're looking at Javascript solutions.

You could try one of the polyfill scripts that add support for newer CSS features to old IE. Either IE9.js or Selectivizr. These two scripts are generally pretty good at adding support for CSS selectors to old IE, but what you're doing here is a real edge-case, and I would not be surprised at all if they didn't cope with it. Give them a try by all means, but don't expect miracles.

Given that, a more manual approach might work better: If you're using jQuery or a similar library, they should be able to select the required elements pretty easily, and you could work from there. (if you're not using jQuery or a library with a built-in selector engine then you'll struggle, but if you're supporting IE7 it would be a surprise to hear you're not using jQuery already)

But the real message that comes out of this is that inline styles and the CSS !important modifier are bad practices and will come back to bite you. And you've been bitten pretty hard.

Upvotes: 1

Related Questions