views:

97

answers:

3

I have a DIV container that is a CSS class defined on the top level. That container also has a style that has a couple elements that should override the main class elements. As far as I understand, this is what it should be doing, but it seems to ignore everything I am putting in there.

/* In the CSS file. */
div.ItemContainer {
    position:absolute;
    left:50px;
    top:15px;
    width:80px;
    height:70px;
}

and In the HTML file:

<div class="ItemContainer" style="left:200px; top:150px;">
    Test text.
</div>

Am I doing something wrong here? If not, any suggestions on how to get this to work? Thanks.

+1  A: 

try !important

left:200px !important;
yomash
That may work, but it would be a workaround. The OP's code should work.
Bart van Heukelom
IE does not recognize the !important flag.
Alerty
In fact, certain versions of IE does not support !important at all or in a standard compliant way.
Alerty
@Alerty: It looks like this page/app might be targeted at iPhones. But IE does support `!important` (buggily) See: http://reference.sitepoint.com/css/importantdeclarations , for example. Also: http://stackoverflow.com/questions/189621/when-does-csss-important-declaration-not-work/189661#189661
Brock Adams
+1  A: 

Sometimes things don't cascade correctly in some browsers. Use the !important flag to override behaviour.

style="left: 200px !important; top: 150px !important"
Aren
In my experience, it does. But whatever you say...
Aren
@Alerty actually, it does. It has (or had) some *bugs* with respect to `!important`, but it has always recognized `!important` and none of the bugs are relevant here.
hobbs
@hobbs: Certain versions of IE does not support it. ;)
Alerty
@Alerty But not versions that anyone uses. Let me say it again. IE6 supports `!important`. *IE6 supports `!important`.* **IE6 supports `!important`.** Were you perhaps referring to the versions of IE that are *older than CSS2*? Because they're the only ones that don't support `!important`.
hobbs
@hobbs: IE6 supports CSS2 in an incorrect way: http://www.quirksmode.org/compatibility.html
Alerty
And yet... it supports `!important`.
hobbs
@hobbs: It does not support it in a standard compliant way.
Alerty
@Alerty I know that. However it does work 99% **and** none of the problems it has affect this question at all **and** I already explained its limitations and the fact that they don't matter to this question **before** you made your repeated incorrect posts.
hobbs
@hobbs: Anyway `!important` is not the solution. `I tried all the suggestions so far, and none of them help. What I've shown above is from a pretty tricky dynamic page with elements created via javascript, so I'm guessing something is going wrong there. Looking into that instead. – Eli Jul 2 at 23:15`
Alerty
+1  A: 

Your code seems to be alright. Have a look at the markup language you are using (HTML/XTML...) to see if it has an error such as a unclosed quotes, missing tag or missing end tag. Another thing that could mess up your style is the use of JavaScript for styling. It is a bad practice to use JavaScript for styling! Have a close look at what you are doing with the use of JavaScript for styling.


iScroll

Using iScroll seems to be the source of your problem. You might want to use a JavaScript library that does not mess with CSS. Also, you could try to modify the library or find a way to bypass what ever you are doing with the library.

You might find something useful in these links:

Alerty
IE7+ has full support for `!important`. IE 5 and 6 have partial support for it. In fact it is interpreted correctly but overwritten if another style declaration follows *later*. No matter what, the OP's code should work without a problem as the style attribute takes first precedence (without `!important` declarations).
poke
@poke: !important was fixed in a later release of IE7. A lot of people still do not find it important to update or to buy a newer operating system. I prefer allowing a majority of people the capability of viewing a site with the same experience than to deny them access because of layout issues.
Alerty
http://stackoverflow.com/questions/189621/when-does-csss-important-declaration-not-work for a good discussion on the subject
Alex
@Alerty please accept that you are wrong wrong wrong when you repeatedly write **lies** on this page.
hobbs
@hobbs: I'll modify my answer to say certain versions of IE, but neither of us are lying. I fail to see your logic.
Alerty