3

I have noticed FF, Chrome and Safari behaving such that if you intervene to the display property of an object, media query does not work anymore on that object property.

Such that, I have prepared a test html code, here it goes [1]...

Do you have any idea not to have this effect? I don't think translating css media query to javascript is not up to generality principles...

Shortly, I would like to change visibility of a DIV both with media query and with javascript when needed (if possible).

[1]: http://paste.ubuntu.com/1046784/ (test scenario)

1 Answer 1

5

When you directly update the "style" of an element, that style will override anything set in CSS (unless the CSS has ! important and the local style doesn't).

To avoid that problem, don't manipulate the style of your elements directly. Instead, add or remove one or more "class" strings, and provide styles (possibly affected by media queries) in the stylesheet. It's generally much nicer to do things that way even when you're not dealing with media queries. It's easier to update style stuff in a CSS file than it is to root around for it in JavaScript code.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.