0

Can some CSS ninja please verify if my thought process is right or wrong.

I have a project with media queries settings css depending on if device is landscape or portrait. If my css sets width of an element to 500px and I modify that width to let say 600px, the element style is modified.

When the device changes orientation - the element style stays at 600px regardless of what my css file is set. Because the element style is higher hierarchy than styling from a css file.

What I need to do is set that element.style('width')='' to more or less erase it.

Am I right? is there a way to get the css file to always override the element style?

Thanks!

1
  • can't, the width is adjustable by user.. i'm using dom element.style('width')='XXpx' is there a better way that will work? Commented Jul 4, 2011 at 5:08

1 Answer 1

3

If you use the !important declaration in a css file it will overwrite any inline styles. So in the example below the width of the div will be 400px.

.example {
    width:400px !important;
}

<div class="example" style="width:600px"></div>

Not sure why you are allowing a user to modify a width though - seems like you'll always get into an undesirable situation. But whatever, this should work :)

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, perfect. The user can modify the width because they have a panel that they can move around.. works kind of like Twitter on iPad but the screen adjusts based on their actions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.