Why put two different position rules in one css selector

Go To StackoverFlow.com

5

Found this is some example CSS I was reading and I'm having a hard time determining why there are two position rules in one selector.

#Div
{
     position:fixed !important;
     position:absolute;
}

What does this accomplish? Isn't the !important element always going to override the position: absolute?

2012-04-05 00:25
by user772110
It's either a browser hack or someone who doesn't know what they are doing - Chris Laplante 2012-04-05 00:26


6

All browsers that support position:fixed will use it, the others fall back to absolute.

2012-04-05 00:28
by binarious
+1 I would think it would make more sense to switch the two around and lose '!important' though - Gary 2012-04-05 00:38
Some browsers may reset the attribute to the user agent default when finding an invalid value. But I'm just guessing :) - binarious 2012-04-05 00:47
@binarious: As far as I know all browsers will ignore an invalid declaration, rather than falling back to the default value. Either way, both this and what Gary describes will work the same: IE6 applies position: absolute while other browsers apply position: fixed - BoltClock 2012-04-05 03:07
@BoltClock'saUnicorn well then I don't understand why so many articels using the method posted by the OP - binarious 2012-04-05 03:08
Because it works? There are many ways to skin a cat. That said, this does exploit two IE6 flaws when only one needs to be exploited (no fixed support), the other being that it ignores important declarations in the same rule and always applies the last one - BoltClock 2012-04-05 03:08
Ads