Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Responsive media query not working in Google Chrome

Tags:

I have written a piece of CSS code to fluidly switch my site layout's width based on the user's screen width. If the user has less screen estate available, the layout's width increases to fill more of the window and leave less whitespace, and if they have more space, the layout shrinks to maintain an appealing look.

I use the following code to achieve this:

#bg{     background:-webkit-linear-gradient(90deg, #0f0f0f 0%,#222222 400px);     background:-moz-linear-gradient(90deg, #0f0f0f 0%,#222222 400px);     background:-o-linear-gradient(90deg, #0f0f0f 0%,#222222 400px);     background:linear-gradient(90deg, #0f0f0f 0%,#222222 400px);     margin-left:auto;     margin-right:auto;     margin-bottom:1.6rem;     border-width:0 0.1rem 0.1rem 0.1rem;     border-style:solid;     border-color:#303030 #101010 #000;     border-radius:0.8rem;     min-width:94.2rem }  @media (min-width: 70rem){     #bg{         border-radius:4px;         border-radius:0.4rem;         width:90%     }  }  @media (min-width: 91rem){     #bg{         width:80%     }  }  @media (min-width: 112rem){     #bg{         width:70%     }  } 

This works just fine in Firefox 30, however Google Chrome always displays the element at 70% width.

Previously, I had also used max-width in the queries, in which case Chrome would do the inverse thing; it would always display the element at 90%, no matter how much I resize the browser window.

The rules are compiled using SASS. What exactly is the problem here? How can I alter the query to work in all browsers?

The affected website can be found at this link.

like image 777
ividyon Avatar asked Jun 21 '14 19:06

ividyon


People also ask

Why are my media queries not working?

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.

How do I add media queries to Chrome?

Activate Media Query Tool To enable it: go into responsive design mode. click the three dots menu in the top right of the screen. click "show media queries"

Why media query is not working in mobile?

Mobile Media Query Not Working If your queries are working in a browser but not on mobile, you might have forgotten to set the viewport and default zoom. This tells the browser to render pages according to the width of the device. Adding it often does the trick for making mobile breakpoints work.


2 Answers

add this line in <head>

<meta name="viewport" content="width=device-width,initial-scale=1"> 
like image 177
Hassan Raza Avatar answered Sep 17 '22 17:09

Hassan Raza


If you're using Chrome (or any browser) on a desktop, the browser zoom should be 100%. No more or no less. Otherwise, responsive doesn't work (use Ctrl + scroll in Windows, or Cmd +/- in Mac to adjust).

like image 24
PlainOldProgrammer Avatar answered Sep 18 '22 17:09

PlainOldProgrammer