Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Media queries not taking effect on browser resize

I'm using media queries to make a mobile version of a website for a client. When i resize the browser the media queries do not take effect, however they do take effect when the site is viewed on each device - i'm just curious as to why the media queries don't take effect when i resize the browser window itself i.e. Firefox.

Any input is much appreciated.

Code i'm using:

    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 720px) {
    #container {
        width: 100% !important;
        }
    }
like image 299
Nikki Mather Avatar asked Jul 30 '13 18:07

Nikki Mather


People also ask

Why media query is not working in HTML?

Media Query Not Working on Mobile Devices If media queries work on desktop and not on mobile devices, then you most likely haven't set the viewport and default zoom. Note: You only need to add one of the code lines above, and usually, the first one does the job.

Can media queries resize based on a div element instead of the screen?

They cannot be used to refer to a certain element on a page. If you need to apply styles depending on the size of a certain div element on your page, you'll have to use JavaScript to observe changes in the size of that div element instead of media queries.

Should I use max width or min-width in media queries?

If you are designing your website for smaller devices first then set your initial breakpoints with min-width, whereas, if you are designing for larger devices first then use max-width. This post discusses min-width, and max-width media features in detail along with relevant examples.

What browsers support media queries?

Media Queries Support CSS Media queries are supported in Internet Explorer (IE) 9+, Firefox 3.5+, Safari 3+, Opera 7+, as well as on smartphones and other screen-based devices.


2 Answers

If you are using attribute: max-device-width or min-device-width, it will work only on devices with that width and will ignore the manual browser resizing.

You should change the attribute to: max-width / min-width.

@media screen and (min-width: 1024px){
  /* some CSS here */
}

Check here:

In CSS media the difference between width and device-width can be a bit muddled, so lets expound on that a bit. device-width refers to the width of the device itself, in other words, the screen resolution of the device.

http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml

like image 185
Aljana Polanc Avatar answered Oct 13 '22 03:10

Aljana Polanc


change your code to -

@media only screen 
and (min-width : 320px) 
and (max-width : 720px) {
#container {
    width: 100% !important;
    }
}

alternately you can keep your previous code and check the responsive nature of your website in local computer by Mozilla Responsive Design View feature - shortcut 'Control+Shift+M'

like image 27
yogihosting Avatar answered Oct 13 '22 02:10

yogihosting