0
<head>
    <style>
        .cdm-tb { width: 960px; height: 90px; }
    </style>

    <script>
        ChangeCssRule(".cdm-tb", "width", "468px");
        ChangeCssRule(".cdm-tb", "height", "60px");
    </script>
</head>

<body>

    <img src='images/testimage.jpg' class='cdm-tb' alt='test' />

</body>

ChangeCssRule is a JS function that works. But when I add a couple media queries to the .cdm-tb style, updating the CSS rules no longer works.

    <style>
        .cdm-tb { width: 960px; height: 90px; }
        @media(min-width: 728px) {.cdm-tb { width: 728px; height: 90px; } }
        @media(min-width: 960px) {.cdm-tb { width: 960px; height: 90px; } }
    </style>

Is there an order of execution concerning media queries I am not understanding? Any suggestions would be appreciated.

2

2 Answers 2

1
<html>
<head>
<meta name="viewport" content="width=device-width">

</head>
<style>
body{background:#000000;}
.cdm-tb { width: 960px; height: 90px; }
@media screen (min-width: 728px)
{
.cdm-tb { width: 728px; height: 90px;}
}

@media screen (min-width: 960px)
{
.cdm-tb { width: 960px; height: 90px;}
}
</style>
<img src='images/testimage.jpg' class='cdm-tb' alt='test' />

</html>

you have to add meta tag view port for responsive design

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

Comments

0

I wasn't able to modify the existing media query values but I did find a work around here: Generating CSS media queries with javascript or jQuery. The work around was to just append a brand new media query on the end of the < STYLE> tag to override any previous settings that were applied:

document.querySelector('style').textContent += 
           "@media(min-width: 468px) {.cdm-tb { width: 468px; height: 60px; } }";

Comments

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.