Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple media queries for different screen sizes

Tags:

css

screen

media

I'm trying to set different image sizes according to the screen resolution, some of them work and some don't. Here's my Code:

@media screen and (max-width: 1280px) {#gallery-1 img {width:375px;}} // for 1280px screens 
@media screen and (min-width: 1366px) and (max-width: 1439px){#gallery-1 img {width:375px;}} // for 1366px screens 
@media screen and (min-width: 1440px) and (max-width: 1599px) {#gallery-1 img {width:428px;}} // for 1440px screens 
@media screen and (min-width: 1600px) and (max-width: 1919px) {#gallery-1 img {width:434px;}} // for 1600px screens 
@media screen and (min-width: 1920px) {#gallery-1 img {width:540px;}} // for 1920px screens 

The code is not working at all for the 1366px and 1280px x 600px screen. 1280px x 960px works with the code for the 1366px. 1280px x 1024 works with the code for the 1440px. Can anybody please help? Thank you!

like image 263
platzchen Avatar asked Nov 04 '13 13:11

platzchen


2 Answers

you don't need to set a maxwidth on your media queries as the next media query overrides it anyway. Try this:

#gallery-1 img {
    width:375px;
}
@media screen and (min-width: 1366px) {
    #gallery-1 img {width:375px;}
}
@media screen and (min-width: 1440px) {
    #gallery-1 img {width:428px;}
}
@media screen and (min-width: 1600px) {
    #gallery-1 img {width:434px;}
}
@media screen and (min-width: 1920px) {
    #gallery-1 img {width:540px;}
}
like image 137
Adrian Roworth Avatar answered Nov 13 '22 05:11

Adrian Roworth


Instead of using

@media screen and (min-width: 1366px) {
/* Styles go here */
}

Use media query differently like

@media (max-width: 1366px) and (min-width: 1441px) {
/* Styles go here */
}

this thing will specifically call out in which limit which styles should be applied.

like image 40
abhishek Avatar answered Nov 13 '22 04:11

abhishek