i2ymiq
Last Updated: September 09, 2019
·
3.257K
· med_hassen

CSS Media queries for different devices

/* Smartphones (portrait and landscape) ----------- /
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/
Styles */
}

/* Smartphones (landscape) ----------- /
@media only screen
and (min-width : 321px) {
/
Styles */
}

/* Smartphones (portrait) ----------- /
@media only screen
and (max-width : 320px) {
/
Styles */
}

/* iPads (portrait and landscape) ----------- /
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/
Styles */
}

/* iPads (landscape) ----------- /
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/
Styles */
}

/* iPads (portrait) ----------- /
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/
Styles */
}

/* Desktops and laptops ----------- /
@media only screen
and (min-width : 1224px) {
/
Styles */
}

/* Large screens ----------- /
@media only screen
and (min-width : 1824px) {
/
Styles */
}

/* iPhone 4 ----------- /
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/
Styles */
}

3 Responses
Add your response

14276

Hi!

Why sometimes min-device-width, sometimes min-width?

over 1 year ago ·
14278

Hi,

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. Lets say your screen's resolution is 1440 x 900. This means the screen is 1440 pixels across, so it has a device-width of 1440px. Most mobile phones have a device-width of 480px or lower, including the popular iPhone 4 (with device-width: 320px), despite it technically having a 640 x 960 resolution. This is due to iPhone 4's retina display, which crams two device pixels into each CSS pixel on the screen. This is true for the Ipad 3 as well; its reported device-width is 768px just like its predecessors, even though its actual screen resolution is 1536px x 2048px. In general width is more versatile when it comes to creating responsive webpages, though device-width is useful when you wish to specifically target mobile devices (and not desktops with a small browser window for example)

You can check more details about this here : http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml

over 1 year ago ·
14281

I asked because I believe this should be part of the tip. ;-)

over 1 year ago ·