Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari ignoring css max-width media queries below a certain point

I'm working on optimizing a responsive site and Safari (both desktop and mobile) seems to be completely ignoring media queries below a certain point. I have code like the following:

@media screen and (max-width: 767px){
    /* Safari responds to css here */
}
@media screen and (max-width: 640px){
    /* css here is ignored by Safari */
}

Firefox and Chrome both respond appropriately. Does anyone have any ideas about what is going on?

You can see the site here: http://kgillingham.webfactional.com. What should happen (and works on FF and Chrome) is that as the site becomes less than 640px the header font in the slider should become a smaller size.

edit: The site has now been updated to use javascript to add a class when the size is less than 640px. That class always uses the smaller font size. This means that it works as expected now, but I would much rather use CSS media queries than javascript so I would still like to see a solution.

like image 932
joshcartme Avatar asked Apr 12 '13 16:04

joshcartme


People also ask

How do you set the minimum and maximum width in media query?

Max-width and min-width can be used together to target a specific range of screen sizes. @media only screen and (max-width: 600px) and (min-width: 400px) {...} The query above will trigger only for screens that are 600-400px wide.

Why my media query is not working in CSS?

CSS declared inline This may be the reason why your media queries aren't working. That is to say, you may have declared CSS within your HTML document. So if this is the case, simply go through the HTML document and remove the CSS declared inline. Alternatively, you can override the inline CSS with !

Do media queries work in Safari?

CSS3 Media Queries is Fully Supported on Safari 13, which means that any user who'd be accessing your page through Safari 13 can see it perfectly.

What is @media in less?

Media queries always begin with @media and consist of two parts: The first part, only screen, determines the media type where a rule should apply—in this case, it will only show the rule if we're viewing content on screen; content viewed when printed can easily be different.


1 Answers

Turns out I was missing a squiggly brace, so I had code like the following:

@media screen and (max-width: 767px){
    /* lots of css */
    .some_selector { padding: 20px; /*<---- missing squiggly brace*/
    /* more css */
}
@media screen and (max-width: 640px){
    /* lots more css */
}

Inserting the missing brace caused Safari to begin working. Other browsers didn't choke on the error which is partially why it was so difficult to track down.

Thanks for the help everyone, I feel pretty silly now.

like image 123
joshcartme Avatar answered Oct 14 '22 03:10

joshcartme