Note that there are some explanatory texts on larger screens.

plurals
  1. POCan !important rules be used in IE's CSS expressions?
    text
    copied!<p>Firstly, <em>I know</em> that CSS expressions are defunct and wrong in so many ways, and also to avoid using <code>!important</code> where possible. This is for a <a href="http://code.google.com/p/cleanslatecss/" rel="nofollow noreferrer">special case stylesheet</a>.</p> <h2>In Short</h2> <p><strong>My question is... Is there any way for a CSS expression to set the <code>!important</code> flag?</strong></p> <p>E.g. this doesn't work:</p> <pre><code>a { color:expression('red !important'); } </code></pre> <p><em>[Edit: thanks to MarmaladeToday's comment below].</em> This also doesn't work:</p> <pre><code>a { color:expression('red') !important; } </code></pre> <p>Can this be done some other way?</p> <hr> <h2>In Detail</h2> <p>What I'm actually trying to do is mimic the <code>inherit</code> value in IE6 &amp; 7. <em>This works</em>:</p> <pre><code>color:expression( this.parentNode.currentStyle ? this.parentNode.currentStyle.color: 'red' ); </code></pre> <p>But I also want to set the <code>!important</code> flag, and <em>this doesn't work</em>:</p> <pre><code>color:expression( ( this.parentNode.currentStyle ? this.parentNode.currentStyle.color: 'red' ) + ' !important'); </code></pre> <p>I'm aware that, in JavaScript, it isn't possible to set <code>!important</code> via an element's <code>style</code> object. E.g. <em>this won't work</em>:</p> <pre><code>element.style.color = 'red !important'; </code></pre> <p>However, it <em>is</em> possible to set <code>!important</code> via the element's <code>style</code> <em>attribute</em>:</p> <pre><code>element.setAttribute('style', 'color:red !important;'); </code></pre> <p>So... are CSS expressions limited to interacting with the <code>style</code> object, and therefore, what I want to achieve is impossible - or is there any way for an expression to affect an element's attributes, or pass <code>!important</code> in some other way?</p> <hr> <h2>Starting a Bounty</h2> <p>No solid answers so far, so I'm starting a bounty.</p> <p>Ideally, I'm looking for a CSS-based solution for mimicking <code>inherit !important</code> in IE6 and IE7, either with or without CSS expressions. (Please do verify that your suggestions work before posting).</p> <p>At least, a link to some authoritative reference telling me that this is impossible would mean I could lay this train of thought to rest - I've not seen anything mentioning the use of CSS expressions with the <code>!important</code> rule.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload