Sie sind auf Seite 1von 118

CSS-Tricks

Search

Home

Videos

Almanac

Gallery

Snippets

Forums

Newsletter

Jobs

Guides

Code Snippets CSS Media Queries for Standard Devices

By Chris Coyier Last Updated On July 23, 2016

Media Queries for Standard Devices

If you think responsive's simple, I feel bad for you son. We got 99 viewports, but the iPhone's just one.
Josh Brewer, March 10, 2010

A major component of responsive design is creating the right experience for the right device. With a gazillion
different devices on the market, this can be a tall task. We've rounded up media queries that can be used to
target designs for many standard and popular devices that is certainly worth a read.

If you're looking for a comprehensive list of media queries, this repository is a good resource.

If you're reaction to this is: you should never base your breakpoints on devices!! You have a good point. Justin
Avery has a nice post on the possible pitfalls of using device-specific breakpoints. Choosing breakpoints based
on your design and not specific devices is a smart way to go. But sometimes you just need a little help getting
one particular situation under control.

Phones and Handhelds

iPhones

/* ----------- iPhone 4 and 4S ----------- */

/* Portrait and Landscape */


@media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2) {

/* Portrait */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}

/* Landscape */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {

/* ----------- iPhone 5 and 5S ----------- */

/* Portrait and Landscape */


@media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2) {

/* Portrait */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}

/* Landscape */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
}

/* ----------- iPhone 6 ----------- */

/* Portrait and Landscape */


@media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2) {

/* Portrait */
@media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {

/* Landscape */
@media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {

/* ----------- iPhone 6+ ----------- */

/* Portrait and Landscape */


@media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3) {

/* Portrait */
@media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: portrait) {

}
/* Landscape */
@media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: landscape) {

Galaxy Phones

/* ----------- Galaxy S3 ----------- */

/* Portrait and Landscape */


@media screen
and (device-width: 320px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 2) {

/* Portrait */
@media screen
and (device-width: 320px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 2)
and (orientation: portrait) {

/* Landscape */
@media screen
and (device-width: 320px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 2)
and (orientation: landscape) {

/* ----------- Galaxy S4 ----------- */

/* Portrait and Landscape */


@media screen
and (device-width: 320px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 3) {

}
/* Portrait */
@media screen
and (device-width: 320px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: portrait) {

/* Landscape */
@media screen
and (device-width: 320px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: landscape) {

/* ----------- Galaxy S5 ----------- */

/* Portrait and Landscape */


@media screen
and (device-width: 360px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 3) {

/* Portrait */
@media screen
and (device-width: 360px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: portrait) {

/* Landscape */
@media screen
and (device-width: 360px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: landscape) {

HTC Phones

/* ----------- HTC One ----------- */


/* Portrait and Landscape */
@media screen
and (device-width: 360px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 3) {

/* Portrait */
@media screen
and (device-width: 360px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: portrait) {

/* Landscape */
@media screen
and (device-width: 360px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: landscape) {

Nexus Phones

/* ----------- Nexus 4 ----------- */

/* Portrait and Landscape */


@media screen
and (device-width: 384px)
and (device-height: 592px)
and (-webkit-device-pixel-ratio: 2) {

/* Portrait */
@media screen
and (device-width: 384px)
and (device-height: 592px)
and (-webkit-device-pixel-ratio: 2)
and (orientation: portrait) {

/* Landscape */
@media screen
and (device-width: 384px)
and (device-height: 592px)
and (-webkit-device-pixel-ratio: 2)
and (orientation: landscape) {

/* ----------- Nexus 5 ----------- */

/* Portrait and Landscape */


@media screen
and (device-width: 360px)
and (device-height: 592px)
and (-webkit-device-pixel-ratio: 3) {

/* Portrait */
@media screen
and (device-width: 360px)
and (device-height: 592px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: portrait) {

/* Landscape */
@media screen
and (device-width: 360px)
and (device-height: 592px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: landscape) {

Tablets

iPads

/* ----------- iPad mini ----------- */

/* Portrait and Landscape */


@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (-webkit-min-device-pixel-ratio: 1) {

}
/* Portrait */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 1) {

/* Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 1) {

/* ----------- iPad 1 and 2 ----------- */


/* Portrait and Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (-webkit-min-device-pixel-ratio: 1) {

/* Portrait */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 1) {

/* Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 1) {

/* ----------- iPad 3 and 4 ----------- */


/* Portrait and Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (-webkit-min-device-pixel-ratio: 2) {

/* Portrait */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 2) {

/* Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2) {

Galaxy Tablets

/* ----------- Galaxy Tab 10.1 ----------- */

/* Portrait and Landscape */


@media
(min-device-width: 800px)
and (max-device-width: 1280px) {

/* Portrait */
@media
(max-device-width: 800px)
and (orientation: portrait) {

/* Landscape */
@media
(max-device-width: 1280px)
and (orientation: landscape) {

}
Nexus Tablets

/* ----------- Asus Nexus 7 ----------- */

/* Portrait and Landscape */


@media screen
and (device-width: 601px)
and (device-height: 906px)
and (-webkit-min-device-pixel-ratio: 1.331)
and (-webkit-max-device-pixel-ratio: 1.332) {

/* Portrait */
@media screen
and (device-width: 601px)
and (device-height: 906px)
and (-webkit-min-device-pixel-ratio: 1.331)
and (-webkit-max-device-pixel-ratio: 1.332)
and (orientation: portrait) {

/* Landscape */
@media screen
and (device-width: 601px)
and (device-height: 906px)
and (-webkit-min-device-pixel-ratio: 1.331)
and (-webkit-max-device-pixel-ratio: 1.332)
and (orientation: landscape) {

Kindle Fire

/* ----------- Kindle Fire HD 7" ----------- */

/* Portrait and Landscape */


@media only screen
and (min-device-width: 800px)
and (max-device-width: 1280px)
and (-webkit-min-device-pixel-ratio: 1.5) {

/* Portrait */
@media only screen
and (min-device-width: 800px)
and (max-device-width: 1280px)
and (-webkit-min-device-pixel-ratio: 1.5)
and (orientation: portrait) {
}

/* Landscape */
@media only screen
and (min-device-width: 800px)
and (max-device-width: 1280px)
and (-webkit-min-device-pixel-ratio: 1.5)
and (orientation: landscape) {

/* ----------- Kindle Fire HD 8.9" ----------- */

/* Portrait and Landscape */


@media only screen
and (min-device-width: 1200px)
and (max-device-width: 1600px)
and (-webkit-min-device-pixel-ratio: 1.5) {

/* Portrait */
@media only screen
and (min-device-width: 1200px)
and (max-device-width: 1600px)
and (-webkit-min-device-pixel-ratio: 1.5)
and (orientation: portrait) {
}

/* Landscape */
@media only screen
and (min-device-width: 1200px)
and (max-device-width: 1600px)
and (-webkit-min-device-pixel-ratio: 1.5)
and (orientation: landscape) {

Laptops

Media Queries for laptops are a bit of a juggernaut. Instead of targeting specific devices, try specifying a
general screen size range, then distinguishing between retina and non-retina screens.

/* ----------- Non-Retina Screens ----------- */


@media screen
and (min-device-width: 1200px)
and (max-device-width: 1600px)
and (-webkit-min-device-pixel-ratio: 1) {
}

/* ----------- Retina Screens ----------- */


@media screen
and (min-device-width: 1200px)
and (max-device-width: 1600px)
and (-webkit-min-device-pixel-ratio: 2)
and (min-resolution: 192dpi) {
}

Wearables

Yes, we're going there. Sure, these might not exactly qualify as "standard" devices quite yet, but they are fun to
look at.

Apple Watch

/* ----------- Apple Watch ----------- */


@media
(max-device-width: 42mm)
and (min-device-width: 38mm) {

Moto 360 Watch

/* ----------- Moto 360 Watch ----------- */


@media
(max-device-width: 218px)
and (max-device-height: 281px) {

The Divi Theme Download the Ultimate WordPress Theme including our advanced Drag &
Drop builder
ads by BSA

Comments

1.

alpaproductions
Permalink to comment# October 13, 2010

Pretty useful! Ill have to try it though.

Reply

2.

carlos

Permalink to comment# January 26, 2011

What are you using to switch between mobile width and full width on your current site?

I dont quite see it in your source.

Reply

Cody

Permalink to comment# February 26, 2013

He isnt using a different width just for mobile. He is using things such as

@media (min-width:500px){/*Class name*/{/*properties*/}}


@media (max-width:499px){/*Class name*/{/*properties*/}}

This just says that any time there is a screen size bigger than 500px, certain styles will be
applied, and when it is below that, it will apply different properties.

test

Permalink to comment# July 5, 2015

I dont quite see it in your source.


Reply
o

Anne

Permalink to comment# October 29, 2015

Hi, I am new to programming. I have a survey that I want to launch and it is possible that my
respondents will not have the same tablets. Can I combine all the scripts for the different
tablets?

3.

Tj

Permalink to comment# February 17, 2011

Just read your post on using CSS for alternate styles for websites based on screen resolution. Great
post.

Im wondering if I can pay you to make me a simple template for HTML emails (that look like text) that
looks good in mobile devices and desktop. Heres the specs

If the screen size is not mobile device then I need the text area to wrap at 350px.

If the screen size is mobile device then I want the text to wrap 100% across the screen (for either
landscape or non-landscape) with a max width of 350px (in case of something like landscape mode
iPad).

I need the text itself to be style font size +1 (so it looks slightly larger then the users normal email
messages).

What Im looking to avoid is using a 350px table to wrap the text and then having the iPhone shrink the
text down smaller then normal Requiring the user to take an extra step zooming in.

Also looking to avoid using end of line breaks at 350px and having those breaks end up mid screen on a
mobile device (looking horrible).

Should be pretty simple for someone into this stuff. Let me know if you can do it and how much.

Reply
o

Burke

Permalink to comment# February 20, 2013

Just FYI, this is impossible if you plan to support all email clients. Gmail strips out the head of
your message so media queries wont work. The best you can do is build a fluid layout and use
text-size-adjust.

Dom

Permalink to comment# October 7, 2013

Go to http://htmlemailboilerplate.com/

Its exactly what you are looking for.

4.

Mark

Permalink to comment# February 23, 2011

Im just at the base of my learning curve on using alternate stylesheets for different devices. Following
your example elsewhere Ive sort of got it working. Im testing it on my HTC Desire Android and for it to
work on this phone Im having to set as follows:

screen and (min-device-width: 1008px) HTC Desire ignores


screen and (min-device-width: 1009px) HTC Desire uses this stylesheet

The Desire is 480800 so theres a part of this Im not understanding!

Reply
o

Chris

Permalink to comment# August 28, 2011

have you used device width, initial scale=1 in your meta? mobile devices sometimes rescale
their viewings

5.

David Nemes

Permalink to comment# June 16, 2011

Here can you find more Media Query Snippets. http://nmsdvid.com/snippets/

Reply

Jbcarey

Permalink to comment# January 5, 2012

This is awesome!!! thanks.

Cer

Permalink to comment# May 9, 2013

This media queries snippet are just great, well organized and very clear.. Thanks a lot
6.

Ronny

Permalink to comment# August 30, 2011

Nexus S reports 533 Pixels in landscape mode. so none of the above snippets will work if the phone is in
landscape mode when you navigate to your site. my iPod on the other hand always reports 320px in
portrait, as well as in landscape mode. Same for iPhone 4. It always reports 320px.

Reply

7.

Omer Levi

Permalink to comment# November 17, 2011

Is this set of media queries suitable for the mobile-and-up approach?

Reply

8.

Jim

Permalink to comment# November 22, 2011

In my testing, the min-width: 321px seems to override most of the others. Is that necessary/helpful? I
notice that you (Chris) dont use it in your code for this site. Looks like youre only using:

@media (max-width: 1350px) {}


@media (max-width: 1200px) {}
@media (max-width: 1024px) {}
@media (max-width: 860px) {}

Thanks!

Reply
o

Arush Sehgal

Permalink to comment# August 1, 2012

You are correct, but Im not sure what the solution is here. Chris?

Cody

Permalink to comment# February 26, 2013

If you use min-width:321px, then max-width:500px, the min width property overrides it because
it applies all styles above 321px.

Mangat Singh

Permalink to comment# August 5, 2016

this format using or not?

9.

shah

Permalink to comment# December 7, 2011

Nice Article .thank u

Hey Guys !!!!!


I Have a Problem
In regards to the media queries working on android browser. I Use Dreamweaver CS5.5. When I tested
there was no change .
When I tested in landscape view it takes the default web browser screen width it is not device screen
width.

Reply

Ryan Lowe

Permalink to comment# December 9, 2011

Same problem. Android browser adopts default stylesheet instead of mobile stylesheet. Testing
on Nexus S.

Ryan Lowe

Permalink to comment# December 9, 2011

I think Ive figured it out. When I use (max-device-width: 800px) it works. I guess @media is
seeing that my Nexus is 480800 and taking the higher number as the width.

10.

Mike

Permalink to comment# January 9, 2012

When I use this to request a stylesheet for retina displays:


<link rel=stylesheet type=text/css href=/css/mobile-retina.css media=only screen and (-webkit-min-
device-pixel-ratio: 2)/>

I cant get the W3 Validator to validate this. The error is: Bad value only screen and (-webkit-min-
device-pixel-ratio: 2) for attribute media on element link: Expected a letter at start of a media feature
part but saw instead.
Is there a way of using the value -webkit-min-device-pixel-ratio mentioned in this post in a way so
that its valid?

Reply

german

Permalink to comment# January 17, 2012

Mike:
I would add Your mobile-retina.css in Your main CSS file?
Example:

/* Start main CSS file */


...
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
/* here come styles from mobile-retina.css */
}
/* End main CSS file */

Marcy

Permalink to comment# February 21, 2012

Nobody really validates HTML anymore since there are so many evolving standards. If your site
works then why do you care?

Eric Sebasta

Permalink to comment# May 31, 2013

No. any css extension that is rendering engine specific does not validate. Anything starting in
-moz for Mozilla or -webkit for example while it works is not technically valid.
o

Laura

Permalink to comment# July 3, 2015

I this thread outdated please? I there more up to date guide for standard media queries??

I am sort of a newbie to media queries, so please excuse me if I seem out of touch with the
latest media queries code. However, I am just reading these comments for the first time and
they are over 3 years old. Does this site have an updated thread please??

11.

BirdYosh

Permalink to comment# January 18, 2012

(orientation : portrait) doesnt validate for CSS3. Are you ignoring that? Or do you have a
workaround?

Thank you.

Reply

12.

Robbiegod

Permalink to comment# January 19, 2012

i am writing right now is a page that will change the background image for each screen device because
the desktop version is going to have hi-res photos on it. So, I dont want to make mobile people
download these super large images. I want my CSS files to be seperate so i am writing my media
queries like this for example:

So a quick question. IF i visit a page that uses media queries does the browser download all of the style
sheets or just the one that has been targeted? In my case, the styles.css should always load and then
the other media queried stylesheets will load depending if they are true or not.
Reply

Nicholas

Permalink to comment# September 22, 2013

Your questions does not have a 100% definite answer, however I was researching this last week
and came to one straight forward way of explaining this. If you are using display:none, you have
a better chance of that element not being rendered by the browser. While if you are using
visibility:hidden, the element you are configuring will be preloaded by your browser. Basically, it
all depends on how the change takes place in your stylesheet to make the object hidden or
shown and of course which browser/platform/device the user is accessing from.

Paul

Permalink to comment# May 6, 2014

If you place all css in one file (including media queries), the device will download all assets
regardless of the devices dimensions, so while you might use display:none to completely
remove the element from the architecture of the website, its assets are still downloaded.

You are best to use a global style sheet, then target each break point setting with its own css
file, this way ONLY that file and its assets will be targeted.

If you load desktop images in your global style sheet, then target smaller devices with smaller
images, overriding the larger, you will be loading both the large and smaller image even
though the larger is not being displayed, it is being loaded, thereby slowing down the load time
of the site for mobile users.

Always best to use separate media query files to target the devices within the break point range
and always use min and max settings to target these devices, because if you use only min size
and overwrite by the next larger size (or smaller size) you are still loading all assets.

13.
Jeremy Mansfield

Permalink to comment# January 23, 2012

Is it possible to target the iphone4+ with a separate media query than other smart phones with the
same min/width size

I ask because my responsive site (http://www.cortac.com) is shaping up nicely on an iPhone4+.


However, in older (2 year old) Androids, etc., the footer doesnt *stick*, and I was hoping to simply
have the footer display: none;

However, by doing so, that also kills my iphone4+ styling where I *do* want the footer to display. The
problem is that the iphone4+ and the normal *smartphone* min/max dimensions are targeting the
same dimensions of 320 and 480 respectively and I am unable to get separate devices with same
width/height ratios to be targeted differently without overriding each other. Any online articles that
talk about this would be greatly appreciated!

Reply

Marcy

Permalink to comment# February 21, 2012

Did you try checking for the existence of a retina display (-webkit-min-device-pixel-ratio)?

Frank Patricci

Permalink to comment# November 5, 2012

LOL!

Jeremy Mansfield: Jesus Lover

Kristin Schaeffer
Permalink to comment# January 15, 2013

Gorgeous site, Jeremy! And I really like how youve broken it up with media queries. I stumbled
on this post searching for the same problem you had getting everything to look the same
cross-phone-browsers. I think this thread may help me. Thanks for posting and keep up the
awesome work.

Paul

Permalink to comment# May 6, 2014

You can not target specific devices with CSS thats where adaptive design comes into play by
mixing together both javascript (or jquery) and css to target specific devices, set break points,
and anything else css can not do, then apply the styles associated by the Adaptive targeting.

Amit

Permalink to comment# November 5, 2016

Amit Nagar! And I really like how youve broken it up with media queries. I stumbled on this
post searching for the same problem you had getting everything to look the same cross-
phone-browsers. I think this thread may help me. Thanks for posting and keep up the awesome
work.

14.

Robbiegod

Permalink to comment# January 24, 2012

Does the trick that german wrote to Mike let you target the iPhone4? iPhone4 and iPhone4S are
the one with the retina display?
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
/* here come styles from mobile-retina.css */
}

That should work right? Just put that in your main css file where you hide the footer but then add a
style in there to display it

Also, i checked out the website too, looks great. One question I have is when i collapse the browser i
notice that you always use the same set of images. Are you planning to keep it that way or will you
optimize it for mobile devices by making the background not as big.

Ive made my site so that it loads a different background image depending on what kind of device it is. I
dont want to download a 150kb-200kb background on my phone when i dont have too.

Reply

15.

Jeremy Mansfield

Permalink to comment# January 30, 2012

Robbie, thank you for your response. I do have the styles for the retina display only, in addition to
regular smartphones, and it does not seem to work on distinguishing between the two. If I eliminate
the footer for normal smartphones, it overrides the retina styles regardless. Seems to be all or nothing
so far.

Yes, thank you for your observation. I indeed plan on loading in smaller background images for the
mobile version. I just have not added in those media queries yet, as this is a responsive experiment for
me in progress.

Reply

Paul

Permalink to comment# May 6, 2014

use this to target specific devices


(function(a){(jQuery.browser=jQuery.browser||{}).mobile=/(android|ipad|playbook|silk|
bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|
iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|
palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|
link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|
50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|
aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|
v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|
ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|
ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|
hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|
go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|
kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|
lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|
mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|
n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|
owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|
psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|
sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|
sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|
50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-
9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|
60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|
your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);

Then call navigator.vendor to determine the device

you should see something like this in the response:


Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML,
like Gecko) Version/4.0 Mobile/7A341 Safari/528.16

16.

chris

Permalink to comment# February 10, 2012

My issue is the same as Marks. I am currently using Bootstrap and it seems like the layout changes
should be made when the page is vertical in the ipad, but the layout doesnt change unless I alter the
media queries from 768px to 769px. Im sure this isnt the way its supposed to be done

This is in the my header.php

&ltmeta name=viewport content=width=device-width, initial-scale=1.0&gt

Reply
17.

ChrisHu

Permalink to comment# February 18, 2012

There are several reasons to use the viewport-width instead of the device-width.
Read more under:
http://www.quirksmode.org/blog/archives/2010/09/combining_meta.html

Reply

Steven

Permalink to comment# February 7, 2013

You sir are a genius. Works like a charm! iphone4+ now show a different css and I can now make
my desktop browser 800px minimum width and not the minimum 1136px (iphone4+)

18.

Run Raksmey

Permalink to comment# February 25, 2012

Hi now i want to put |Home| page in my web. can you express to me.

Reply

19.

Rats

Permalink to comment# March 5, 2012


@Run Raksmey

Sure via fed express, $1.78 per pixel.

Reply

20.

Ram Ratan Maurya

Permalink to comment# March 16, 2012

Hello,

I used about media queries in a recent project, when I enter into landscape mode from portrait mode
on iPad it appears scaled i.e. its already zoomed. I want it to show on original page zoom on both
portrait and landscape mode.

Any solution for the same?

Reply

Peter Wooster

Permalink to comment# August 16, 2012

Yes there are solutions for this. The simplest is to use Chrome instead of Safari as this is a mobile
Safari bug. You can also look at my post on Forrst for various
workarounds http://forrst.com/posts/Fixes_for_Mobile_Safari_Zoom_Orientation_bug-2S0, I
currently use the accelerometer based fix.

Ashley

Permalink to comment# February 3, 2013

You can overcome this with some Javascript.


Add this to your <head> element.

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Then:

<script type="text/javascript">
if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
var viewportmeta = document.querySelector('meta[name="viewport"]');
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0,
initial-scale=1.0';
document.body.addEventListener('gesturestart', function () {
viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-
scale=1.6';
}, false);
}
}
</script>

sourabh

Permalink to comment# December 23, 2015

hey can u please say what u meant by..


when u enter into landscape mode from portrait mode on ipad it appears scaled?

21.

Jonathan

Permalink to comment# April 5, 2012

Hi!

Am I really the only one with issues using media queries and Desktop Safari?!

@media only screen and (min-device-width : 321px)

targets safari browser on desktop aswell, regardless of size of browserwindow.


Reply

Tony Shaw

Permalink to comment# August 22, 2012

You are not the only one with safari issues. I am having the same issues with safari picking up
@media css as well in ANY resolution. the problem is i did a @media body {overflow:hidden}
and safari will not scroll now lol

Paul

Permalink to comment# May 6, 2014

you need to add a max-width break point as well the style you set in min-width starts at the
size and goes up and is inherited.

Eric Sebasta

Permalink to comment# August 22, 2014

that makes complete sense!

You said match every screen device with over 320 pixels. That is every device except very old
phones, and you asked it to look and device-width, not width, so it does not care about the size
of your browser window at all only the devices width.

22.

Robbiegod
Permalink to comment# April 5, 2012

just a stab in the dark to help you out, but you are saying the minimum width needs to be 321px, which
your safari is at least 321px wide, so of course its going trigger on there.

Try using max-width instead.

Look at the code example above, you see for smartphones he uses (max-width:320px;).

Reply

Jonathan

Permalink to comment# April 5, 2012

Yeah I know, but Im refering to this in the examples:

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

Changing it to min-device-width doesnt help either.

Ri

Permalink to comment# November 26, 2013

Instead of using @media only screen and (min-device-width: 321px) {}

Use @media only screen and (max-device-width: 480px) {}

Works like a charm!!!

23.
KevinM1

Permalink to comment# April 6, 2012

What would be the heights associated with the widths? Im weary about above-the-fold problems.

Reply

24.

robbiegod

Permalink to comment# April 7, 2012

You would have to research each device you want to target to find out the heights or find the phone
with the lowest resolution to use as a baseline.

Honestly, you should just structure your page so all important vital things are at the top and less vital
things below that.

Amd make it so your 2ndary things are partly visible so they know tp scroll, but I think it is mostly
implied.

Look at other mobile sites and measure.

Reply

Marcy

Permalink to comment# April 9, 2012

The page fold is a mythpeople know how to scroll. Especially on mobile web.

25.

Vic Dinovici

Permalink to comment# April 9, 2012


Hello everyone,

Im pretty new to this media queries thing so I may be missing something but I try to implement
lessframework on a page and something weird is happening on my iPhone4:

when is in portrait it is resizing the page just fine but when I rotate to landscape the page goes out of
boundaries
if I refresh the page while in landscape the page is looking just fine

I also noticed exactly the same thing on their website http://www.lessframework.com.

Does anyone know how to fix this?

Thanks,
Vic

Reply

Laurens

Permalink to comment# May 2, 2012

I had the same problem on the Ipad. This is a ios bug.


Small javascript fixed the problem.

See: http://stackoverflow.com/questions/5434656/ipad-layout-scales-up-when-rotating-from-
portrait-to-landcape

26.

Jared Booye

Permalink to comment# April 10, 2012

Hi Chris,

I am a GUI designer. When designing for a mobile site iPhone retina display I traditionally use a
resolution of 640960. When designing for mobile or iPad in PS should I compensate for the hi res
display or just design at the 320px (72 DPI)/768px (72 DPI)?

Thanks for the help.


Jared

Reply

Adriano

Permalink to comment# April 13, 2015

Hi Jared,
I would work matching one of the highest resolution supported today like the iPad mini retina
that is:

2048-by-1536 resolution at 326ppi.

Then I would export scaled down versions if needed.

27.

Marc

Permalink to comment# April 21, 2012

Hey there!

Thanks for the useful info. Im a newbie & hungry for good advice & coming across great content &
design inspires me even more.

I love your input boxes with the images in them! Can you tell me how or where i could find out how to
use them?

Thanks, marc

Reply

28.

@kerns
Permalink to comment# May 3, 2012

I really love the idea of a boilerplate snippet for queries, but the portrait and landscape queries for
smartphones (more accurately, for iPhones) appear broken in my tests.

Im also curious why we wouldnt want to leverage device orientation for this task also seems slightly
more platform agnostic. Detecting portrait mode would then look something like

@media only screen


and (max-device-width: 320px)
and (orientation: portrait) {

/*-- Styles --*/

Reply

29.

Steve Roberts

Permalink to comment# May 11, 2012

I am having problems understanding your approach to this. I have been working with a framework
lately and working on a responsive grid system. Maybe I am understanding this differently but I set my
responsive parts in a separate stylesheet to another stylesheet I call global or base where in this goes
the main grid system. In this part of your script

/* Desktops and laptops */


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

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

you have 1824px which yes is understandable, very large screens, larger then my imac monitor so
therefore the grid system can expand. But then you have 1224px, ok this is larger then the resolution of
my macbook but 1200px at least is my imac size and to me the standard size of any screen round a
bout.

Now what Im getting at is this example:

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

GLOBAL STYLESHEET
#container {width:980px}

Now I feel in my (round a bout) 1200px size monitor, these two sizes are gonna class. Why not delete
(min-width : 1224px) and set it at a much larger pixel rate.

I hope this makes sense. Now heres how ive done it which to me makes more sense. Now between
768px and 1824px I can then create the grid system as normal to whatever size i feel and when it goes
below 768px or above 1824px, it changes. But their is no mixing.

/* Large Desktop and Laptop Screens (devices and browsers) */


@media only screen and (min-width: 1824px) {}

/* Tablet Devices, Desktop and Laptop Screens */


@media only screen and (max-width: 768px) {}

/* iPads (portrait and landscape) */


@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {}

/* Smartphones (portrait and landscape) */


@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {}

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

@media print {}

The only other idea I have come up with is that your not creating the css anywhere else and the 1224px
is what it is but what if a grid is 960 or 980px which is typical.

Also you have a and (min-device-width : 768px) and (max-device-width : 1024px). I know its a device-
width, will that not effect it on a desktop or laptop computer?

Sorry about the blunt questions, but im just trying to understand it and I ask a lot of questions. :)
Reply

Paul

Permalink to comment# May 6, 2014

Use your base/global style sheet for styling, and your media query files for the layout
dimensions and text overrides. You will never have a problem with clashing of sizes

30.

Jeff H

Permalink to comment# May 22, 2012

Is there a way to distinguish between an iPhone 4 and an iPad 3? Just using the pixel-ratio doesnt
seem to work

Old iPads are distinguished, but not the new ones

Thansk,

JH

Reply

Mike

Permalink to comment# June 5, 2012

I am just learning, but this might be what you are after?

/**********
iPad 3
**********/
@media
only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

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

/**********
iPhone 4+
**********/
@media
only screen
and (min-device-width : 320px)
and (max-device-width : 480px)
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

@media
only screen
and (min-device-width : 320px)
and (max-device-width : 480px)
and (orientation : portrait)
and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

31.

Gazu

Permalink to comment# May 24, 2012


Hello
how can I make a special styles for the Iphone4 retina in landscape position?
I can apply the portrait.. but when turn my iphone.. this lost the styles

this is right?

Reply

32.

Vic Dinovici

Permalink to comment# May 24, 2012

Gazu, here is how I style for landscape with media queries:

@media screen and (max-width:480px) and (orientation: landscape){}

Also to fix the safari bug I put this in the head:

<meta name=viewport content=width=device-width, initial-scale=1.0, minimum-scale=1.0,


maximum-scale=1.0, user-scalable=no />

Reply

Theo

Permalink to comment# November 18, 2012

You saved my day, thanks!

33.

Gazu

Permalink to comment# May 24, 2012

Thank you very much Vic


Reply

34.

Joseph Carr

Permalink to comment# June 6, 2012

We have recently launched a new website that uses responsive design.


However we are hearing from some users that the site is not responsive on some mobile devices:
HTCs, Windows phones, etc.

When I test in an emulator the devices highlighted the site looks fine, but still for some devices it seems
not to work.

Any ideas?

http://www.zappybaby.be/nl
http://forum.zappybaby.be

Reply

35.

Vishwa

Permalink to comment# June 7, 2012

i cant use media query in bigcommerce template, did not work, shal i need any java script for it? pls
help

Reply

36.

Vishwa

Permalink to comment# June 7, 2012


no thanks , now i used media queries well

Reply

37.

sonali

Permalink to comment# June 26, 2012

Hi,

we are planning a tablet version of our existing website with entirely different content. Now, just want
to know the css media query for the same catering all the tablets i.e. android, ipads, noble nook,kindle
etc.

I am new to this field actually.

Reply

38.

Marc

Permalink to comment# June 26, 2012

When I switch from portrait to landscape on my iphone the site doesnt align properly. It overflows. I
have a 480px style set so what else am I doing wrong? Can anybody help me?

Reply

ToMarc

Permalink to comment# July 2, 2012

You should use percent based values inside of the stylesheet, and set a max and min width for
the link to the stylesheets. Everything should be fluid except of the breakpoints, but the
viewport above 900/960px can have a fixed value.
o

Gruber

Permalink to comment# July 2, 2012

Maybe i know whats your issue, on iPhone when you switch from portrait to landscape there is
a bug screwing user zoom, therefore it overflows (if i understand your problem correctly). If
thats the case, you have to zoom out to manually fix it isnt it?
Theres a nifty script here http://github.com/scottjehl/iOS-Orientationchange-Fix, that can fix it
for the user automatically, and it works pretty well!

39.

Gruber

Permalink to comment# July 2, 2012

hei there ive been trying to do something to say sort of for anything with device-pixel-ratio&gt1 use
this .
Ive tried something with the not operator :
@media not screen and (max-device-pixel-ratio: 1) { stuff }
Is it worth in your opinion?
Btw i was wondering if vendor prefixes are still needed for this or just the vanilla

Reply

Gruber

Permalink to comment# July 3, 2012

meh the whole thing is wrong X)


i meant
@media screen and (not max-device-pixel-ratio:1) {stuff }
still it seems not to be working. I guess the general min-device:1.5 is far better.
o

Damir Abdic

Permalink to comment# January 27, 2014

@Gruber Thank you for the http://github.com/scottjehl/iOS-Orientationchange-Fix


That worked for me. Cheers. Damir

40.

canis

Permalink to comment# July 3, 2012

All this pixel-fiddling does not make sense. With iPad 4 it is clear: you have to ask for the physical size
and not for the pixel-resolution. even on a 640-pixel wide iPad a two column design of a web page does
not make sense.

Reply

41.

canis

Permalink to comment# July 5, 2012

I now realized my responsive web page. See http://mm.ymir.de . It not only adapts to small devices, but
also to small browser windows. So just narrow the width of your browser and look how the page
changes. Also the pictures are responsive: When loading the page they are loaded according to your
window size.

Reply

o
Joseph Carr

Permalink to comment# July 10, 2012

http://responsive.is/www.bostonglobe.com

42.

Martin Dub

Permalink to comment# July 13, 2012

Have you tested which size (min-width/max-width) can target the new MacBooks Retina display?
Im not sure if this new high definition laptop screen resolution is conflicting with the above media
query for large screens (min-width : 1824px).

Reply

43.

Niall

Permalink to comment# July 17, 2012

Hey peops, just to let you know that if youre using Less with the Less.app on Mac, it doesnt accept the
original device-pixel-ratio of 1.5 or indeed the opera equivalent of 3/2.
All device-pixel-ratios need to be 2 only.
Just thought it might help someone out there!
Peas and korn.

Plus, Chris what is your view on the HTML5 form validation strictness of the URL input type. I really
have to include my http:// really? What is up with that

Reply

44.

JCaveman
Permalink to comment# August 7, 2012

Marcy is obviously new to web dev.

Reply

45.

Will Egan

Permalink to comment# August 15, 2012

I love you!

Reply

46.

Tom Copeland

Permalink to comment# August 21, 2012

Hey Chris, great info. Any ideas on how to check using PHP for a particular screen size, in this case for
an iPhone, or max-screen-size: 320px?

Reply

47.

Vishwa

Permalink to comment# August 23, 2012

I used media query it works in browser when i re-sized my browser, but it not work with mobile device,
ipad, android , android mobile screen size width 320px, but it takes @media only screen and (min-
width:768px) and (max-width:1024px) this query , what i do?

Reply
48.

canis

Permalink to comment# August 23, 2012

Dont forget the metatag in the html page:

And for selection of the design think about using the width and height in inch or cm instead of pixels.
See my website

Reply

49.

canis

Permalink to comment# August 23, 2012

meta name=viewport content=width=device-width, initial-scale=1

Reply

50.

swati

Permalink to comment# August 24, 2012

pls tell me cross browser compatible media query for retina

Reply

51.

Vishwa
Permalink to comment# August 24, 2012

Use ithis website for ur refrense http://css3please.com/

Reply

52.

f1ss1on

Permalink to comment# August 24, 2012

Hey guys, when it comes to responsive there are many ways to accomplish your goals. Probably one of
the most easy and common is the way Chris describes here.

One that I have learned is to use increase max widths to target general smartphone devices such as the
Samsung Galaxy 3 and others.

@media only screen


and (min-device-width: 320px)
and (max-device-width : 640px) {
/* Your Styles Here*/
}
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Your Styles Here */
}

Reply

53.

f1ss1on

Permalink to comment# August 24, 2012

Umm, what Marcy? Nobody validates HTML anymore? Looks like you may need to work in another
field.
Google loves valid HTML, and so does its crawlers. If you dont have valid HTML, you dont have a site
worthy of indexing. This is one thing that makes HTML 5 so great. It is semantic. Just because it works
does not mean its working for you or your clients.

Please refer to this if you have questions.

Google SEO Test Google Prefers W3C Valid HTML & CSS?

Reply

54.

Marcy

Permalink to comment# August 24, 2012

Look, I work in the industry and Im speaking from my personal experience. I know web standards and I
write code by hand every day. If I run into a problem I cant spot easily, validation is one potential tool
but no one at my agency validates as part of our regular workflow anymore. Thats just the way I see it.

Reply

55.

Dan

Permalink to comment# August 24, 2012

@f1ss1on: Youre parsing words there. Marcy isnt saying dude just write shitty broken HTML, its cool!
Shes saying you shouldnt worry too much about validators because they dont take into account the
complexity of our rapidly evolving ecosystem. Validators often puke on code which is perfectly fine.

Reply

56.

canis

Permalink to comment# August 25, 2012


f1ss1on: But what will your code do on a Samsung Galaxy 4 and an iPhone 5? Why do you ask for pixel
size instead of physical sizes? It will only save your employment changing the same code again and
again to add each new device.

<script type="text/javascript">
// set size for image processing on server
function setSize() {
document.cookie='resolution='+ window.innerWidth +'; path=/';
}
&lt/script>
<meta name="viewport"
content="width=device-width,
nitial-scale=1"
/>
<link rel="stylesheet"
type="text/css"
href="css/small.css"
media="screen and (max-width: 14cm)"
/>
<link rel="stylesheet"
type="text/css"
href="css/medium.css"
media="screen and (min-width: 14cm)
and (max-width: 20cm)"
/>
<link rel="stylesheet"
type="text/css"
href="css/large.css"
media="screen and (min-width: 20cm)"
/>
<body onLoad="setSize();" onResize="setSize();"&gt

Reply

57.

JCaveman

Permalink to comment# August 25, 2012

Marcy also said that the page fold is a myth. Which is another case in which she is wrong. It has nothing
to do with whether people know to scroll or not- its the notion of captivating your audience quickly.
Putting the right content above the fold entices them to scroll in the first place.

Sounds like Marcy needs to find a new agency.


Reply

Dan

Permalink to comment# August 25, 2012

What I dont understand is your need to make insulting personal comments like this. Debating
ideas is awesome insulting somebody and questioning their right to practice a discipline is
immature and unprofessional.

Marcy

Permalink to comment# August 25, 2012

How about making this more about media queries & sharing knowledge and less about cutting
people down? Everyone will benefit from more code and less negativity.

Paul

Permalink to comment# May 6, 2014

Page fold is not a digital term its from the days when newspapers (remember them?) were
sold on the corner and the publisher used the most exciting stories above the fold of the paper
to sell them. Print folks evolved into digital and carried terms that were not interchangeable
Browsers scroll, so there is no such thing as above or below the fold Ive seen many websites
that only scroll left/right, so where is the fold on those? People interact with websites, thats
why we build them, so why should everything be above the fold? A waste of design ethics
when one does that.

58.
JCaveman

Permalink to comment# August 25, 2012

It is my opinion that misinformation passed around by people in my industry who claim to be experts is
one of its biggest downsides. Especially when they present their opinions as fact, like Marcy did. Junior
developers are led astray every day by comments from people like this.

Your responses are over dramatic. I did not personally attack Marcy; she tried to use her agencys
practices to qualify a misguided statement. I responded to it.

Reply

Dan

Permalink to comment# August 25, 2012

Again, youre stating your opinion as fact, and the opinion of others as misinformation.

If you think Im being dramatic by pointing that out, I have nothing more to add.

59.

Jcaveman

Permalink to comment# August 25, 2012

Marcy, I apologize for insulting you. Ill word my comments differently in the future.

Reply

60.

Tim

Permalink to comment# September 7, 2012


Hi all, becareful with Media Queries! They are not pixel accurate.
Some times they are off only 20 pixels but other time they are off up to 150 pixels However, even few
pixels is very bad when trying to target a certain mobile phone screen.

Reply

61.

vhinmanansala

Permalink to comment# September 22, 2012

Hi, im wondering why

@media only screen


and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Your Styles Here */
}

is not working when i test the site im working using ipadpeek. but works when i removed the device-
is there any difference between them? thanks, this is my first time developing responsive website so im
a little confused. please guide me.

Reply

62.

MIhail Yakimenko

Permalink to comment# September 23, 2012

Today this article very help me :) Thanks!

Reply

63.

Surya Osborne
Permalink to comment# September 23, 2012

Vhinmanansala, I am just reading Ethan Marcottes Responsive Web Design and he mentions that min-
width and min-device -width are two different things. I guess the essence is that a screen is not
considered a device.

Reply

64.

Lil Fab

Permalink to comment# October 3, 2012

Hey guys.. i need your help..

when i try to use this code..


@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation :
portrait) {

but.. when i change the code to..


@media only screen and (min-width : 768px) and (max-width : 1024px){

it can be work correctly.. im so confuse bout what is happen with that.. please explain to me..

btw,this is my blog http://idwds.blogspot.com who i work for progress..please check

Reply

65.

Lil Fab

Permalink to comment# October 3, 2012

Hey guys.. i need your help..


when i try to use this code.. it doesnt work correctly
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation :
portrait) {

but.. when i change the code to..


@media only screen and (min-width : 768px) and (max-width : 1024px){

it can be work correctly.. im so confuse bout what is happen with that.. please explain to me..

btw,this is my blog http://idwds.blogspot.com who i work for progress..please check

Reply

Chathura Wijekoon

Permalink to comment# November 4, 2013

Dear Lil Fab,

It depends on your approach to code. Actually it really works fine without the term and
(orientation : portrait) because in most devices it is the default view. But in some cases (there
may be), when the device is kept horizontally, the CSS code should be changed. It depends on
your design + the way of coding. Mostly if you use Percentage values for specifying width,
margin as well as padding, the removed term is not needed. But if you mention the values in
PX (Pixels), you have to use both (orientation : portrait) as well as (orientation :
landscape) separately.

Thanks!

66.

Digamber

Permalink to comment# October 17, 2012

@media only screen


and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}

I used this option to hide some elements for one of my site.


It works fine for iPhone but doesnot work on other android phones

Reply

67.

Pamela

Permalink to comment# October 19, 2012

I have been using it like this to make it web & mobile responsive.

@media only screen and (min-width: 0px) and (max-width: 480px) {


.wrapper {margin: 0 auto; max-width: 98%}

container {margin: 2% auto; width: 96%}

@media only screen and (min-width: 481px) and (max-width: 719px) {


.other_sized_properties
}

Reply

68.

isaac

Permalink to comment# October 25, 2012

What if I want the same Media Query to target the iPad AND the desktop (max-width: 768), without
duplicating the code? How to do that?

Reply
o

Kusumakar Pant

Permalink to comment# June 27, 2014

Follow The Link :


https://stackoverflow.com/questions/13076371/media-query-for-ipad-and-desktop-max-width

69.

damu

Permalink to comment# November 8, 2012

You yourself seems to be doing other way round. from larger screen to smaller one. not mobile first.

Reply

70.

spike

Permalink to comment# November 9, 2012

I always use this post as a reference, but what about the new 7-inch devices?

Reply

71.

Webbyra

Permalink to comment# November 16, 2012


I also use this as a reference but as spike said how about the new 7 Nexus and the iPad Mini. What is
the best with for this?

Reply

72.

Colin

Permalink to comment# November 30, 2012

If anyone here needs a way to quickly generate valid custom media queries or need to look up other
device specific presets, I wrote a free media query tool called Media Query Builder which you can find
here -> Media Query Builder

Reply

73.

Ben

Permalink to comment# December 16, 2012

You seem to be missing the ability to target both ipad and iphones:

@media only screen and (min-device-width: 768px) and (max-device-width: 1024px),


@media only screen and (max-device-width: 480px {

Reply

74.

Ravi Suryawanshi

Permalink to comment# December 26, 2012


This is information is helpful, but is there any way to write minimum media queries and work on all size
devices.

Reply

75.

tim

Permalink to comment# January 1, 2013

Great post, very handy.

I just found something strange that might save people a lot of wasted time with media queries on
Android devices:

Im developing a mobile site and for some reason, a 540960 phone running Android Jellybean would
only pick up the 360-459px wide stylesheet. When I commented out this stylesheet from the header,
the phone totally ignored the others, even the one that specifically targets its resolution.

<link rel="stylesheet" type="text/css" media="only screen and (min-device-width:540px) and (max-


device-width:800px)" href="mob_vhigh.css"/>
<link rel="stylesheet" type="text/css" media="only screen and (min-device-width:480px) and (max-
device-width:639px)" href="mob_high.css"/>
<link rel="stylesheet" type="text/css" media="only screen and (min-device-width:360px) and (max-
device-width:479px)" href="mob_mid.css"/>
<link rel="stylesheet" type="text/css" media="only screen and (min-device-width:0px) and (max-
device-width:359px)" href="mob_small.css" />

After a ton of research, it turns out that the default browser zoom setting does not actually zoom in the
browser per se, but rather ignores its physical resolution, and pretends to have a smaller one. After
some experiments:

o Close zoom loads small.css,

o Medium zoom loads mid.css and

o Far loads the proper stylesheet for the screens actual resolution.

It would appear there is no way to force the users browser to load the proper size stylesheet if their
settings are different. Just thought Id share this, its wasted a lot of my time, and finally I can move on :)
Hope it helps

Reply
o

Tim

Permalink to comment# January 17, 2013

Hi again, heres a few more things Ive since learnt about the subtleties of Android devices:

There are several attributes that can be applied the the tag that alter the way they handle zoom.
One of these is: content="target-densitydpi=device-dpi"

What this does is prevents the device from zooming on the page when it loads. This solved an
irritating zoomed-on-load issue I suddenly had with the iPhone 4s. Users can still scale (if youve
allowed it), it merely targets the devices actual DPI rating, instead of relying on the often
unpredictable automatic zoom. My meta tag now looks like this:

&lsaquo;meta name="Viewport" content="target-densitydpi=device-dpi, width=device-


width"/&rsaquo;

This allows for the layout to adjust completely based on any display. The only hitch is the OS. For
some reason, I cant for the life of me get it to load on a HTC 7 Trophy windows phone without
being zoomed in. Any thoughts? This is the only OS that seems to cause problems now. Even
Blackberries work fine.

In another tweak, Ive updated my media queries in an attempt to ignore most tablets while still
catering for ludicrously high-DPI phones, such as the HTC Droid DNA (19201080, wow). To do
this, Ive simply added another media query with a new condition below the main one:

&lsaquo;link rel="stylesheet" type="text/css" media="only screen and (min-device-width:540px)


and (max-device-width:960px)" href="mob_vhigh.css"/&rsaquo;
&lsaquo;link rel="stylesheet" type="text/css" media="only screen and (min-device-width:961px)
and (min-webkit-device-pixel-ratio:2) and (min-device-pixel-ratio:2)"
href="mob_vhigh.css"/&rsaquo;

This way, the phones load like normal, but any display larger than 960px must have a very high
DPI display to access the styles, so hopefully this will be phones only. Its not perfect, as I
havent had a chance to try it on the Retina iPad (DPI anyone?), but it is designed to quickly
provide a clear divide.

Rather than try and guess how high-res the next generation of phones will be, and have the site
inevitably break on some new device in the future, I thought it made more sense to simply
allow no limit and instead exclude the devices I didnt want by using media queries. Having your
mobile layout designed for small screens appear on a iPad makes you feel like a spoon-fed kid,
as the buttons are now big enough to smash with your fists instead of point with a finger.
76.

Mike

Permalink to comment# January 6, 2013

I found that some of the media queries here a bit haphazard. For example, the smartphone landscape
query is min-width:321px my desktop browser when larger then 321px wide will run the stylesheet
intended for smartphones. Seen how iOS+Safari doesnt consider itself a handheld device,
using @media handheld and (... does not work, so I found that some were clashing with others were
they shouldnt have been. After many frustrating hours I went looking and found this question on Stack
Overflow, Media query ipad vs iphone4

The media queries are being used to specifically target a device width, pixel density(css ratio) and the
orientation. Leaving very little for one device to use another stylesheet not intended for it. Although
this maybe slightly more to write out, you get the consistency across all devices and I have never had
any headaches using this method since.

Reply

77.

Gustavo C

Permalink to comment# January 17, 2013

I am pretty new with media queries. I have a website I am creating a mobile version for. When I check
the site in iphone 4s portrait, 320px wouldnt cover 100% the width. I need to push it to 375px to make
it cover the width of portrait view. Any suggestions?

I am using: inside code


and html { -webkit-text-size-adjust: none; } inside css
the media querie I am using is:
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi)

Great Blog!! Thanks in advance

Reply
78.

viv

Permalink to comment# January 17, 2013

I have tried the same media queries for wordpress test site loaded on localhost. I used online
responsive design tool http://ipadpeek.com/ . This tool fails to catch landscape and portrait mode
queries. But while I tested localhosted wordpress site directly by changing screen resolution of my pc
with windows 7 in portrait and landscape its works.

Reply

79.

Carlos

Permalink to comment# February 4, 2013

I know article is from a while back, but has anyone had an issue with max-device-width and having
rendering issue.
My impression was that the max-device-width only rendered on phones, tablets, and mobile devices,
not on desktop browsers.
This happens when the browser is set and the initial load of the css file with the @Media query loads.
So if I have

@media screen and (max-width:500px), screen and (max-device-width: 1280px){/* My mobile styles
here */}

the desktop browser or screen resolution of the desktop is set at 1280px, it will actually render the
1280px styles mobile styles and not the desktop styles. Did browser makers roll max-device-width
into their browser builds? Any pointers or insite would be great.

Thanks.

Reply

80.
Mittal

Permalink to comment# February 14, 2013

Hi!

You have used proportion for iPhone 4, but what proportion will work for iPhone 5?

Reply

81.

Chris Dill

Permalink to comment# February 14, 2013

I have built my first truely responsive site, with a lot of help from CSS Tricks. I built it in SCSS with lots of
media queries using breakpoints as outlined by Chris C. My question is- I have only user min-width and
max-width (No min-device-width or max-device-width). Is this incorrect? As far as I can tell my site is
working fine across all devices, though testing UserAgents is a pain. Most of my testing comes from
resizing the browser in Chrome, IE and FF, and then using Chrome Dev Tools to test on Galaxy Nexus
and also on my wifes iPhone. Here is an example of my breakpoints.

@mixin breakpoint($point) {
@if $point == 1600 {

@media (max-width: 1600px) and (min-width: 1280px) { @content; }}

@else if $point == 1280 {

@media (max-width: 1280px) and (min-width: 1024px) { @content; }}

@else if $point == 1024 {

@media (max-width: 1024px) and (min-width: 800px) { @content; }}

@else if $point == 800 {

@media (max-width: 800px) and (min-width: 640px) { @content; }}

@else if $point == 640 {

@media (max-width: 640px) and (min-width: 320px) { @content; }}

@else if $point == 480 {


@media (max-width: 480px) and (min-width: 320px) { @content; }}

@else if $point == 320 {

@media (max-width: 320px) and (min-width: 0px) { @content; }}

Reply

Martin

Permalink to comment# March 10, 2013

I am entirely new in this topic. But this seems very interesting. Could you drop an example what
the @content does mean and/or where and what shall be stated in it?
Thanks a lot.

Chris Dill

Permalink to comment# March 19, 2013

Martin- Sure! With the above code, I can use SCSS and mixins to easily make my site mobile
responsive. Rather than creating a huge block of CSS at the bottom of my stylesheets and
putting all my mobile CSS there, I add in my mobile CSS as I design my normal CSS. I then use a
gem which moves everything to the end for production. Moving forward with the above
breakpoints, my CSS might like like this:

.region-menu .navigation ul.inline, ul.links.inline {


@include breakpoint(640) { display: block; float: left; padding-left: 0; width: 160px; }}

As you can see, when SCSS compiles my style sheets, it will yield the following CSS:

@media (max-width: 640px) and (min-width: 320px) {


.region-menu .navigation ul.inline, ul.links.inline { display: block; float: left; padding-left: 0;
width: 160px; }}
o

Chris Dill

Permalink to comment# March 19, 2013

My above illustrations was simple but when you use this for an entire site it becomes super
powerful. When I need to go back and edit the screen width of one div only on mobile devices
at 640px, I simply go to that class in my CSS and make changes- I dont need to scroll through a
page of mobile CSS to make changes.

As Chris Coyer said the above way(using mixins and SCSS) is the way your brain wants to
connect the dots, so why organize things differently. Since I have started to do this, I can just
code mobile as I go. I can put together a sites CSS and responsive all at once, rather than two
separate items.

Anas Abudayah

Permalink to comment# July 23, 2013

Thanks its work with me without frameworks :)

82.

Christian

Permalink to comment# February 28, 2013

Hi Chris. Great article. I often refer back to it. I was just thinking that a lot has evolved and come about
with mobiles and tablets since you wrote this article back in October 2010. Smaller tablets have been
released and some mobile resolutions have gotten bigger. Has this blurred the lines somewhat with
your advised media queries for different devices? Or would you say its largely unchanged?

Reply
83.

Chris Hunt

Permalink to comment# March 4, 2013

Ive been doing some testing on this and using a sony xperia s it seems to think that device width
changes with orientation (720px then 1280px).

This would lend one to use something like this to target Android:

@media only screen


and (min-device-width : 720px)
and (max-device-width : 1280px)

The problem with this is that it overlaps with the iPad and using min-device-pixel-ratio is not enough to
separate them when you get to the iPad 3 as they both have that as 2

Does anyone know how to make android behave and yet not get my mobile site to appear on the ipad.

Reading this article http://stackoverflow.com/questions/12061127/css-media-queries-on-nexus-7-


display-resolution-not-working-in-code lends one to think that actually Android is going to be a swine!

Thanks
Chris

Reply

84.

Martin Dub

Permalink to comment# March 8, 2013

IF NOT TOUCH = standard desktop

Because browser vendors dont support the NOT selector from W3C I had to rely on JavaScript /
jQuery to isolate the CSS that I didnt want to show on iOS and Android device.

<script type="text/javascript">
//detect if browser supports touch
var is_touch_device = 'ontouchstart' in document.documentElement;
if(is_touch_device){
$('body').addClass('touchDevice');
}else{
$('body').addClass('notTouch');
};
</script>

Reply

85.

Sandeep

Permalink to comment# March 12, 2013

This article is awesome. I am gona use it.

Reply

86.

Martin Dub

Permalink to comment# March 19, 2013

This detailed browser compatibility table of the viewport (and some related items) from Peter-Paul
Koch will help anyone interested in this subject in separating the facts from the utopias.

http://www.quirksmode.org/mobile/tableViewport.html

Reply

87.

Gajen

Permalink to comment# March 26, 2013

Thanks for sharing this great article


but how can we use pixel-ratio mediaquery?

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

Reply

88.

Chris Hawkes

Permalink to comment# March 28, 2013

I have a website Noobpost Im trying to figure out how many media queries max-width sizes I should
use, right now I have four, but it doesnt seem to work well with landscape views. It also appears I need
to position everything in a percentage to make it more fluid.

Reply

89.

Al

Permalink to comment# April 4, 2013

Any advice on what to do for large screens?

/* Large screens ----------- */


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

Im particularly concerned about line length becoming unreadable.

Reply
90.

Chris Dill

Permalink to comment# April 4, 2013

You could always just keep the content centered (or left aligned) on the page at a normal width, say 960
or 1024px which would allow it to be readable. To fill up the extra space on the sides you could use a
gradient, clever shadows, or some images to fill up the blank space. My site maxes out at 960px so it
looks the same on 1600 wide monitors, and 1900 wide monitors and beyond. A word of advice- when
designing for large screen, testing or actually designing for a large screen is really helpful- it is hard to
visualize a large screen when working on a 13 laptop.

Reply

91.

Biju Subhash

Permalink to comment# April 6, 2013

Hi, I have some question, in ipad protrait mode


you have specified the min-device-width:768px and max-device-width:1024px and orientation portrait
and the same values you given for landscape too. Actually, when viewing with portrait in ipad the max-
device-width will be 768px right? How the max-device-width be 1024px.

Reply

92.

Conor

Permalink to comment# April 7, 2013

Is there a correct meta tag to go with this? Im trying to target the iPhone4 and below screen widths
(and not the iPad2 and above screen widths). But this isnt even working for iPhone4s..

Reply
93.

Colin Daniel Lafferty

Permalink to comment# May 7, 2013

This is an informative article however i would approach responsive design much the same as we
currently do for fully fluid layouts. My personal approach is semi fluid in nature with responsive design
only to enhance the content.

If for example we apply a fixed width on the container (div as the most semantic selector) Then we can
simply target that by simply applying a max width, minimum width and auto for backwards
compatibility. Of course will work for semi modern browsers this is the best option in my opinion. We
can scale this up or down based upon a percentage and change the width constrictions and there we
have a complete fluid and responsive design.

Of course other elements needs to be specifically styled, rearranged or sometimes hidden (i would not
recommend) by using media queries.

Reply

94.

chris

Permalink to comment# May 11, 2013

Hi,
I am working on a website to make it responsive.

1) Mobile phones including iphone series using a css file (includes portrait and landscape layouts with
@media),

2) Tablets & ipads using a css file (includes portraits and landscape layouts with @media),

3) and desktop version css (which for large, medium and small break points usig @media spearated.)

Is there a way to accomplish the complete workaround some thing like this

link href="desktop.css" rel="stylesheet" media='screen and (min-width:100px) and (max-


width:1280px)' css file for desktop version
link rel="stylesheet" media="only screen and (device-width: 768px) and (device-height: 1024px) and
(-webkit-min-device-pixel-ratio: 1)" href="ipad.css" for ipads & tablets

link href="iphone.css" rel="stylesheet" media='only screen and (max-device-width : 650px)' for


mobiles, iphones only

I know I might be wrong here, as I am very new to this.. Please help me.

Thanks in advance

Chris

Reply

95.

Tom

Permalink to comment# June 11, 2013

CSS-tricks saves my day once again! Thank you!

Reply

96.

Rafiul Alom

Permalink to comment# July 3, 2013

Whats the best solution for IE8 or bellow browser support for media query?

Reply

Preston McCauley

Permalink to comment# August 18, 2013


Your text to link here is a polyfill for using media queries with IE 8 below.

97.

Xavier

Permalink to comment# July 18, 2013

Hello, what about new smartphone with high resolution such as the sony xperia Z for exemple.
Its resolution is 1920 1080, this will be a problem isnt it ?

Reply

Mohamed

Permalink to comment# March 28, 2014

@media only screen and (-webkit-min-device-pixel-ratio: 3) and (max-device-width:1920px) and


(orientation : landscape) { }

@media only screen and (-webkit-min-device-pixel-ratio: 3) and (max-device-width:1080px) and


(orientation : portrait) { }

98.

aneeskodappana

Permalink to comment# July 27, 2013

this is an useful information about responsive web design!


W3schools.com has missed about real media queries !

Reply
o

John

Permalink to comment# August 23, 2013

Thanks for this guide. I am trying to figure out why you specified orientation for ipad, but not for
smartphone..

Shouldnt the smartphone media queries look like this:

@media only screen


and (min-width : 321px) and (orientation : landscape)
{
/* Styles */
}

@media only screen


and (max-width : 320px) and (orientation : portrait)
{
/* Styles */
}

Instead of:

@media only screen


and (min-width : 321px)
{
/* Styles */
}

@media only screen


and (max-width : 320px)
{
/* Styles */
}

It seems you omitted the orientation from these smartphone media queries, but specified them
for ipad? Is the orientation needed for phones or only tablets?

Thanks,
John
99.

Alex Goretoy

Permalink to comment# August 24, 2013

http://thesassway.com/intermediate/responsive-web-design-in-sass-using-media-queries-in-sass-32

/* Smartphones (portrait and landscape) ----------- */


$media-smartphone-portrait: "only screen and (max-width : 320px)";
$media-smartphone-landscape: "only screen and (min-width : 321px)";
$media-smartphone-portrait-landscape: "only screen and (min-device-width : 320px) and (max-device-
width : 480px)";

/* iPads (portrait and landscape) ----------- */


$media-tablet-ipad-portrait-landscape: "only screen and (min-device-width : 768px) and (max-device-
width : 1024px)";
$media-tablet-ipad-landscape: "only screen and (min-device-width : 768px) and (max-device-width :
1024px) and (orientation : landscape)";
$media-tablet-ipad-portrait: "only screen and (min-device-width : 768px) and (max-device-width :
1024px) and (orientation : portrait)";

/* Desktops and laptops ----------- */


$media-desktop: "only screen and (min-width : 1224px)";

/* Large screens ----------- */


$media-large: "only screen and (min-width : 1824px)";

/* iPhone 4 ----------- */
$media-iphone-4: "only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-
pixel-ratio : 1.5)";

Reply

100.

Damir

Permalink to comment# October 14, 2013

Great article man, yes its been 3 years since the article was created but I still find it useful :)
Reply

101.

Matthew Stapleford

Permalink to comment# October 15, 2013

I have used these media queries a few times now so very thankful that this great resource is available.

Thought I would just share that it helped me to resolve a few style issues to swap the portrait and
landscape smartphone media queries around so that for the smartphone media queries it went:

Smartphones (portrait and landscape).

Smartphones (portrait).

Smartphones (landscape).

This helped to stop some of the styles being over written on some phones.

ipad and everything else seemed to work just fine as they are.

Reply

Matthew Stapleford

Permalink to comment# October 15, 2013

ok, just ignore my comment above about swapping the media queries around. I have just
noticed a missing } which was causing the styles that followed the missing } not to work. Doh!
Should have seen that one!

102.

Griffen Fargo

Permalink to comment# November 11, 2013


This is just one heck of a nice resource to stumble upon!

Thanks again CSS-Tricks, you guys continue to produce quality workI I use on a daily basis!

Reply

103.

Amani Icy

Permalink to comment# November 18, 2013

hi , iI have just tried this snippet some how it is not working for me. It doesnt set the right CSS based
on device or when i resize the screen in my browser. So below is what works s fine for me. It allows me
to apply css on both Phones and desktop with small / resized screen size

`@media only screen and (max-width: 480px), only screen and (max-device-width:480px) {}//for mobile
phones
@media only screen and (max-width: 768px), only screen and (max-device-width:768px) {}//for tablet
with medium screen
@media only screen and (max-width: 960px), only screen and (max-device-width:960px) {}//for tablet
with large screen`

Reply

104.

Al Lemieux

Permalink to comment# November 26, 2013

When using device-width, can that be tested in the browser?

Reply

105.

Chris Dill
Permalink to comment# November 26, 2013

Al,

I know this is perhaps not the answer you were looking for, but why do you need device-width? Do you
have a specific reason for using it? I normally build my sites using Min/Max width which I code in using
SASS breakpoints, and when I go to production I leave them be. The only way in which I could see
myself using a device-width tag would be for some sort of mobile app based on HTML.

With Min/Max width, you are also allowing for new devices as they emerge, no matter what the device
dimensions are. I like to develop for all sizes- meaning that as I use breakpoints I want my sites to look
99-100% at every width, even if it is in between normal device widths. With Min/Max width you can
test this by dragging your browser around.

In other words- unless you can name a reason to use device width, stick to Min/Max width.

Reply

106.

ramesh

Permalink to comment# December 10, 2013

hello i have Problem in media query

i have use two media query

1
@media only screen
and (min-width : 768px)
and (max-width : 1024px)
and (orientation : portrait) {}

2.
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
}

=> I have work this condition proper but when i rotate device from landscape to portrait or portrait to
landscap at that time condition not taken without page refresh

Reply
o

Ri

Permalink to comment# December 10, 2013

add <meta name="viewport" content="width=device-width"> in the head

107.

Frank

Permalink to comment# December 26, 2013

Specific style for specific query why its not working without important

for example

@media only screen and (max-width: 320px) {.class1 { width:100%;} }

@media only screen and (max-width: 480px) {.class1 { width:60%;} }

@media only screen and (max-width: 768px) {.class1 { width:80%;} }

Reply

108.

Patrick Chester

Permalink to comment# January 6, 2014

I havent tried this code yet but does anyone know if this works?

Reply
109.

Lee Design

Permalink to comment# January 8, 2014

Hi Patrick and Frank given the evolving nature of mobile platforms, fixed widths are less flexible than
percentage settings- so describing a set dimension now may well compromise A N Other platform in
the future. And make more work for you.

Thus a % dimenion is better than a px setting.

Good Luck!

Reply

110.

Nagarajan

Permalink to comment# January 9, 2014

Hi All,

Kindly advice screen width for Nook Color device

With Advance Thanks,


K. Nagarajan

Reply

111.

john

Permalink to comment# January 28, 2014

Does this work with 5 years old mobiles as well?

Reply
112.

Daniel

Permalink to comment# January 30, 2014

While previously Ive tweaked ready-made solutions for responsive web apps, 2013/2014 are for me,
professionally, the years of building responsive markup from the ground up for SharePoint 2010 and
2013. Ive used these @media queries with great results. They work on nearly ANY mobile device,
provided the devices viewport resolution fits these parameters. Using these queries you can
hide/display content containers (divs and whatnot) to create distinctive experiences for your users,
based upon the device they use to access your web app.

Im VERY impressed with this sites responsive design, not just how the content changes widths but the
attention you guys have paid to EVERY piece of the UI, especially the nav and the banner ad. Really
impressive, CSS-Tricks, Im subscribing and look forward to gleaning a lot. Great job.

Reply

113.

Thiyagarajan Harish

Permalink to comment# February 12, 2014

This tutorial is really good but why doesnt this media queries working in ie9 is there any special code 2
make it happen

Reply

Paul

Permalink to comment# May 6, 2014

works perfectly in IE9. Try adding this to the head section.


114.

yennefer

Permalink to comment# March 18, 2014

So what about new bigger smartphones, do we still use max-width: 480px? But their resolution is much
bigger now, with iphone 4S having 960px and latest Nexus much higher does it mean on those devizes
users will see desktop version of the site? Im a bit confused

Reply

115.

Daniel Kemper

Permalink to comment# April 3, 2014

A very informative page to which I continue to refer, thank you!

Reply

116.

Paul

Permalink to comment# May 6, 2014

min-width, min-device-width, max-width, max-device-width, min-height, min-device-height, max-


height, max-device-height are all different.

If you use min-device-width or max-device-width, make sure you are also defining min-width and max-
width (same goes if youre targeting height, and yes people targeting heights does work).

Also at the very minimum use this in your head section but preferably use this

If you use only @media only screen and (min-width: NNNpx) and no max, expect troubles but they are
solvable try to break your code to what is the architecture (dimensions and sizes) and what is design
(colors and imagery) and have separate files Architecture files should have min/max defining start
and stop points, while min- can carry design element transformations upward (or downward depending
on if you start mobile first or not).

Reply

117.

Paul

Permalink to comment# May 6, 2014

min-width, min-device-width, max-width, max-device-width, min-height, min-device-height, max-


height, max-device-height are all different.

If you use min-device-width or max-device-width, make sure you are also defining min-width and max-
width (same goes if youre targeting height, and yes people targeting heights does work).

Also at the very minimum use this in your head section but preferably use this

If you use only @media only screen and (min-width: NNNpx) and no max, expect troubles but they are
solvable try to break your code to what is the architecture (dimensions and sizes) and what is design
(colors and imagery) and have separate files Architecture files should have min/max defining start
and stop points, while min- can carry design element transformations upward (or downward depending
on if you start mobile first or not).

Reply

118.

Paul

Permalink to comment# May 6, 2014

seems to be a problem accepting code

Also at the very minimum use this in your head section <meta name=viewport
content=width=device-width, initial-scale=1.0> but preferably use this <meta name=viewport
content=width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no, target-
densitydpi=device-dpi>

Reply
119.

sam

Permalink to comment# May 7, 2014

Hello,

I just need to add this css in my style and thats it?

Reply

Zeshan Ahmed

Permalink to comment# May 7, 2014

Yes, and add styles of course. Just in case you dont know, you also need to add a View Port
meta tag in your of html file.

120.

ALIREZA

Permalink to comment# May 9, 2014

your website is very helpful. when i have any problem in web designing in see your ideas and they are
almost perfect.
thank you man.
thanks GOD because we have someone like YOU.

Reply

121.
Anthony

Permalink to comment# May 18, 2014

hello, my website isnt responsive. i am using joomla 3.3.0, how can i make this responsive, which when
open in a mobile device it will fit on its screen size and not changing or shuffling any images, it should
be look like exactly as it is in the desktop browser. can anyone help me?

Reply

122.

Anhony

Permalink to comment# May 19, 2014

Ive found it, I just remove the width=device-width in the meta tag at index.php and viola! my website
fits on the screen without any @media tags!

Reply

123.

Michael Jon Ward

Permalink to comment# June 5, 2014

Just what I was looking for, many thanks! Developing a funky calendar that just wont work on a
mobile Well, not yet anyway! ;)

Reply

Trevor Franks

Permalink to comment# April 4, 2015

Funky calendar for a mobile just add This stops the keyboard from opening
124.

Hany Sobhy

Permalink to comment# June 24, 2014

Hello,
Does iPads (portrait) query target only portrait?
or it should be :

@media only screen


and (min-device-width : 768px)
and (max-device-height : 1024px) {
/* Styles */
}

Reply

125.

Jon

Permalink to comment# July 2, 2014

I built this into a quick site so thought id share it. Very basic, changes colour and content when the
screen is re-sized. http://demo.slickdesign.com.au/responsive-template/

Reply

126.

Gerard

Permalink to comment# July 14, 2014

Let me share my @media queries. Im using this scheme on my own WordPress theme and at the
moment its working very well. What do you think of it?
@media only screen
and (max-width : 1024px) { }

@media only screen


and (min-width : 769px)
and (max-width : 1024px) { }

@media only screen


and (max-width : 768px) { }

@media only screen


and (min-width : 481px)
and (max-width : 768px) { }

@media only screen


and (max-width : 480px) { }

@media only screen


and (min-width : 321px)
and (max-width : 480px) { }

@media only screen


and (max-width : 320px) { }

Its important to remember that max-width and min-width include the pixel referenced. For example,
min-width: 768px includes the 768px position, the same occurs with max-width: 768px. Its used twice
and we have less control. On these cases, its better to add one pixel more to the min-width; for
example, min-width: 769px.

Scheme:
= 769, <= 1024
= 481, <= 768
= 321, <= 480
<= 320

Reply

Adam

Permalink to comment# August 24, 2014

Thanks a lot Gerard! This was really helpful.


o

Pali Madra

Permalink to comment# September 12, 2014

Thank you Gerad for sharing the code. It is handy.

Bryn

Permalink to comment# November 20, 2014

Yes this is critical if you are showing and hiding certain elements using css. I would not use -
device- or when you resize the browser it will look horrible. Just an FYI. I never use -device-, I
dont see the point because all devices will fall into the above @media queries that Gerard
posted. Keep these on file and thanks for sharing.

Laura

Permalink to comment# July 3, 2015

Hi Do you have this posted somewhere online where I can bookmark it to find fast please?? I
am looking for an online guide that I can use for reference for current and future projects as it
appears that this one is out dated. Thanks in advance for your reply.

127.

Gunnar

Permalink to comment# July 15, 2014

Hi,
Im wondering why so many different pixel-sets of different media-querys exists to somehow cover
every potential screen resolution. What will happen if in maybe one year a complete different
resolution will be required because of new hardware? Isnt there a way to be more flexible and to work
with proportions of a screen based on the actual font-size e.g. with the attribute em ?

Reply

128.

Michele

Permalink to comment# July 23, 2014

Im using @media only screen and (max-width: 768px) etc. in my css file, but I want images in my main
html pages to show or not show depending on the screen size. How do I control that? Have you done
that before? I just want to pop in a different image if screen size is smaller than the 1024px.

Reply

129.

vir s

Permalink to comment# July 23, 2014

hi guys,
here you can use the following for devices:
@media query only screen and (max-device-width: 480px){
/*your styles for a 480px device*/
}

Reply

130.

Muhammad Kashif

Permalink to comment# July 26, 2014


Hi

my problem is that when i use @media (max-width: 320px) then page works fine . but below that .
when i write code for @media (max-width: 800px) then 320 does not work just @media (max-width:
800px) works fine ,,,,in short both doesnot work at the same time
anyone can answer ?
will wait :)

Reply

131.

Mar

Permalink to comment# August 2, 2014

Hey Chris, thank you for your useful work!


Will you upgrade this post in the near future?
Bye

Reply

132.

tozman

Permalink to comment# August 6, 2014

Muhammad,

Use the word and between the different conditions


examples :
@media (min-width: 321px) and (max-width: 800px) {}
@media (max-width:320px) {}

Reply

133.
Nitesh

Permalink to comment# August 10, 2014

can you please tell the media query for Ipad mini. The media query for IPad is not working for IPad
mini. Please help me for this

Reply

Nitesh

Permalink to comment# August 11, 2014

@media screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-device-
pixel-ratio: 1){

134.

manoj kushwah

Permalink to comment# September 16, 2014

You are right but my problem is a responsive media in overview for tablet and iPhone in use your media
query not smartness.

Reply

135.

adnan

Permalink to comment# October 15, 2014

Hi,
I am trying many media query but my website not convert in responsive style in Samsung Galaxy S3, on
all devices site open in responsive style.
any one can tell me right method and right media query for Samsung Galaxy S3.

Reply

Jean the Web Machine

Permalink to comment# October 20, 2014

Does this work?

http://nmsdvid.com/snippets/#

136.

Kevin Jackson

Permalink to comment# October 17, 2014

How do responsive design code writers address phones that have more pixels wide than the old phones
did. For instance, my cell phone (ZTE Warp Sync) has dimenions of 1280 x 720 pixels (not the tiny 340px
Ive been seeing in tutorials and sample codes) with a pixel density of 293.72. 1280 (landscape) nor 720
(portrait) is considered phone size any of the media queries Ive been seeing. Some of this code would
render a site I make like a desktop, rather than a phone unless Im missing something.

Reply

137.

laminlay

Permalink to comment# October 28, 2014

how to write responsive template step by step tutorial

Reply
138.

laminlay

Permalink to comment# October 28, 2014

hi

my code not work @media (max-width:320px) {}

Reply

139.

Michael

Permalink to comment# November 1, 2014

Hello folks.
I want to target a certain device using a specific browser.
Now how do I accomplish that? do I nest the media queries?
example:

@media screen and (min width) and (max width) {


@media (-webkit- etc) {
}
}

The device is nested in the screen parameters.

Excuse the code, but you get my point.


Or do I use

@media screen and (-webkit-min-device-pixel-ratio:0) and (min-width : //px) and (max-width : //px)

So far I have had no luck with both.

Any help will be appreciated.


Thanks,
Michael

Reply
140.

Antonio

Permalink to comment# November 5, 2014

So, its seem to me that Ive been the whole time setting the breakpoint false:

@media(max-width:768px)
@media(min-width:768px)

I thought that was the propper way. I have had a lot of problems with devices 768px wide. Now I know
why :|

Reply

141.

John Gerome

Permalink to comment# November 11, 2014

Keep It Simple

http://bradfrost.com/blog/post/7-habits-of-highly-effective-media-queries/

Reply

Glen Pavelich

Permalink to comment# April 18, 2015

RE to John Geromes post: Keep It Simple.


http://bradfrost.com/blog/post/7-habits-of-highly-effective-media-queries/

I am liking this approach thanks.


Question: If I put absolutely everything in ems (ie all elements, text, etc) and the layout in % (or
should this also be ems?)- can you share a simple suggestion for the minimum number of media
queries to use and the em values.

142.

Patrick

Permalink to comment# November 13, 2014

Hi,
i have a little question. I wrote this in my HTML-Code:

This is only an example. My problem is that when i write an other alternative stylesheet with the same
code like i wrote in this comment, the stylesheets dont overwrite the others when I change the
browser-width oder -height. Is this the mistake: (min-width: 0px, max-width: 800px) ?
Must i write the code like this: (min-width: 0px) and (max-width: 800px) ?
Hope my english is good enough to understand me.
I would be lucky about an answer.
Thank you

Reply

143.

surender sharma

Permalink to comment# November 15, 2014

HI i am using (landscape and portrait) for screen size (1024768). But again when i am using this
method for screen size (736414) then its not workign. Any Suggestion ? and also plz tell me that is this
method can see in desktop browser?

Reply

144.

cn arabia

Permalink to comment# December 7, 2014


Hi! is this code works with mini iPad please
/* iPads (portrait) /
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/ Styles */
}

if not please i need it thank you .

Reply

145.

Shahbaz Akhtar

Permalink to comment# February 26, 2015

Thank a lot is working fine.

Reply

146.

David Englund

Permalink to comment# March 7, 2015

I am using the Responsive Theme. What if I want to hide my sub-menu items on the desktop,
but show them on the mobile? I use the Responsive Menu plugin for mobile, which provides a nice
slider expand/collapse look for menus there. But, on the desktop I dont want sub-menus to show. The
main menu items (e.g., About) will take you to that section/page of the website, where a sidebar
navigation will then be used from that point on for all the associated pages.

Reply

147.
zan

Permalink to comment# March 19, 2015

Thanks for this. Really helpful. :)

Reply

148.

tamtam

Permalink to comment# March 20, 2015

And why there is no Windows phone devices ?

Reply

149.

JT

Permalink to comment# April 5, 2015

Chris is a superstar of a CSS pro, but also a very nice dude. I emailed him a couple of times and he
always responded to me. I give you and Paul Irish a lot of props.

In the previous version of this article, Chris put everything in one big section. It was very helpful. I did
the same thing below

Reply

150.

Natalie

Permalink to comment# April 8, 2015

Thanks for the updated queries, they work great.


Reply

151.

Najeh

Permalink to comment# April 18, 2015

And why there is no Windows phone devices ?

Reply

152.

Brian

Permalink to comment# May 7, 2015

Hi,

I have a general question regarding media queries.

Is it possible to target individual screen sizes instead of using min-width and max-width etc

I would like to start on the laptop sizes:

1024 x 768

up to

1920 x 1080

Then eventually work into mobile devices, but I found it particularly difficult to target that way. I have
tried lots of ways but it just seems that if I use min-width, max-width for example, I usually end up
changing the styles for several resolutions with only one media query. Any solutions to this? I know a
lot of you go through this (when starting out), but what have you done to resolve this issue? Any tips
and/or suggestions?

Thank you
Brian

Reply
153.

Carlie

Permalink to comment# May 28, 2015

Hello.

I have two div containers for food menu items. One is called menu-container and is a class the other is
mobile-menu and is an id. I want to show just .menu-container on the desktop and just #mobile-menu
on phone and tablet. I have the max-width set to 1047 and the min-width 1048. When I view it mobile
everything looks and works great but when I view it on the desktop both menus show.

This has been driving me crazy and I am not sure how to resolve this issue.

Thanks,
Carlie

Reply

154.

Greggman

Permalink to comment# May 29, 2015

These media queries dont seem to work on iOS 8.3 (havent tested older OSes). Unless Im missing
something. For example heres a simple test. For iPhone4/4s the background should be red. For
anything larger it should be blue.

But it ends up being red for iPhone5/5s, iPhone6, iPhone6Plus. Its blue for iPadAir, iPad Retina,
Desktop.

How do I get it work for iPhone4/4S only? (basically shorter screens)

<!DOCTYPE html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

<meta name="HandheldFriendly" content="True">


<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0,
maximum-scale=1, user-scalable=no, minimal-ui">
<meta name="format-detection" content="telephone=no" />
<style>
body { background-color: blue; }

/* ----------- iPhone 4 and 4S ----------- */

/* Portrait and Landscape */


@media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2) {
body { background-color: red; }
}
</style>
</head>
<body>
Testing
</body>
</html>

Reply

155.

wady

Permalink to comment# June 9, 2015

I wrote the 4 standard media queries with bootstrap.It is ok.


But it is not ok in pixels between the media queries because I used padding or margin.
How I can solve this problem and are many other media queries?

Reply

156.

mukesh

Permalink to comment# June 10, 2015


hi i wants to now media query for the landscape and Portrait width and height

Reply

157.

hiremwfor.com

Permalink to comment# June 13, 2015

This is really good!!

Reply

158.

Luke

Permalink to comment# June 24, 2015

Thanks for the write up. This is a great resource!

Is it possible to target a particular screen width AND HEIGHT? For instance, weve developed a touch
screen kiosk/web app thats nothing more than a responsive website tailored to a specific touchscreen
monitor width and the usual mobile sizes. The issue comes in the bleed-over of target sizes via min-
and max-widths causing a layout fix on the touchscreen to break the layout on mobile devices. If theres
a way to target a specific width WITH a specific height, that might fix our issue.

Any help would be greatly appreciated!

Reply

159.

Nate

Permalink to comment# June 25, 2015


It seems like the best idea is to choose the widest portrait of the cell phones and simply make ALL
portrait-size mobile device design start at that size. Rather than collapsing columns and stuff at 480px,
youll do it at 736px width instead because of of the iPhone 6.

Thats the simplest.

But, isnt there something much simpler that Zurb Foundation is doing? And what about device-aspect-
ratio instead of pixels?

Reply

160.

Ken Swarthout

Permalink to comment# June 30, 2015

Man, Im having trouble with this media query stuff. I followed a tutorial on how to build a navigation
bar. I built my navigation bar off the tutorial. Its a bit different. I just took the basic idea from the
tutorial. Anyway, this is my problem, when the screen is smaller, the nav bar changes. You can click the
nav bar. It opens up a vertical navigation bar (I call this a mini-menu). While the mini-menu is open, if
you resize the browser and make it larger than 840 pixels, the old navigation bar is misplaced. You can
see what Im talking about at my site. http://JetBBS.com/test2.html. Do you have any ideas how I can
fix this? Ive tried just about everything I could think of! I think I need to do something in the jQuery
code (http://JetBBS.com/js/click.js) but Im not sure what. jQuery isnt my strong suit. Thanks!

Reply

161.

Aeakanshi Agarwal

Permalink to comment# July 9, 2015

I want to known the difference between media query and breakpoints,is there is any difference
between both of them,
if yes then please Reply
thank you.

Reply
162.

Al

Permalink to comment# July 23, 2015

Any particular reason why screen is the target and not all as in

@media all and (min-width: 768px) {}

Reply

163.

Hkan Olsson

Permalink to comment# August 2, 2015

Sorry but can someone explain how and when this article is helpful.

Example:

The query in the iPhone 4 and 4S section (copy/pasted below) is going to effect a lot more devices than
iPhone 4 and 4S.

/* iPhone 4 and 4S /
/ Portrait and Landscape */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2) {}

Its going to effect for example:


iPhone 5
iPod Touch
LG Optimus G
Samsung Galaxy Note
Samsung Galaxy Note 2
Samsung Galaxy S5
Samsung Galaxy S3
Samsung Galaxy Nexus
LG Nexus 4
Microsoft Lumia 830
Sony Xperia S
..and many many more devices. So whats the use of spec this as iPhone 4 and 4S?

Another thing. In the query how do the (max-device-width: 480px) relate to iPhone 4 and 4S though
the device-width for these two devices is 320px?

Reply

Spork Schivago

Permalink to comment# August 2, 2015

I think what the developer was showing was the media queries for the various iPhone stuff.
Yeah, itd work with other devices, but it definitely works with the iPhone 4 and 4S. I do believe
thats why hes grouped it under the iPhones section. Theyre basically saying hey, this is the
media query for iPhone 4 and 4S. Other phones that use the same resolution will be included as
well, but if youre looking for the code to support iPhone 4 and 4S, here ya go.

Unnie

Permalink to comment# August 5, 2015

For iphone 4 and 4s the maximum device width is 480px which is for the landscape mode.

164.

Hkan Olsson

Permalink to comment# August 5, 2015

For iphone 4 and 4s, device-width would probably be 480px in landscape mode but only if these two
devices were Android phones.

Device-width works differently on IOS and Android. For Android its (usually/not allways) two (2)
device-width. One for the short side in portrait orientation and the other for the long side in landscape
mode.
However, in IOS there is only one (1) device-width. Its the shorter side, no matter what orientation. So
actually, for the iphone 4 and 4s the device-width is 320px even in landscape orientation.

Another problem is that different browsers respond differently to device-width. Example: The Android
default browser and Dolphin (but not Chrome, Opera, Firefox) use physical values not CSS pixels which
is the norm.

All this together means that using device-width for the page layout is not very far from using random
numbers :|

Reply

165.

Wasim Khan

Permalink to comment# August 24, 2015

Cool Stuff,

What about the bigger screens, that exceeds 1244px like 1824px.

Can we use

@media screen
and (min-device-width: 1800px)
and (max-device-width: 2200px)
and (-webkit-min-device-pixel-ratio: 1) {
}

Reply

166.

Frank @tekshrek

Permalink to comment# September 6, 2015

Grandios! :-D

Im very happy. Thank you.

Reply
167.

sbrewitt

Permalink to comment# September 13, 2015

Im not a developer at all but trying thank you to everyone whos posted here. Its helped me. Can
anyone tell me what I have two ads returned in this code? Or how I need to correct it? Very grateful.

.adslot_1 { width: 300px; height: 250px; }


@media (min-width:300px) { .adslot_1 { width: 320px; height: 50px; } }
@media (min-width:500px) { .adslot_1 { width: 320px; height: 50px; } }
@media (min-width:600px) { .adslot_1 { width: 320px; height: 50px; } }
@media (min-width:800px) { .adslot_1 { width: 320px; height: 50px; } }
@media (min-width:900px) { .adslot_1 { width: 300px; height: 250px; } }
@media (min-width:1024px) { .adslot_1 { width: 300px; height: 250px; } }

<script async src=http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js>


(adsbygoogle = window.adsbygoogle || []).push({});
var resizeTimer;

function resizer() {
googletag.pubads().refresh([window.Leaderslot]);
}

window.addEventListener(resize, function(){
clearTimeout(resizeTimer);
resizeTimer = setTimeout(resizer, 250);
});

Reply

168.

sbrewitt

Permalink to comment# September 13, 2015

I think this is the better way to post my previous question. Apologies.


Im not a developer at all but trying thank you to everyone whos posted here. Its helped me. Can
anyone tell me what I have two ads returned in this code? Or how I need to correct it? Very grateful.
You an see the code here:
Reply

169.

Sean Cannon

Permalink to comment# September 14, 2015

I turned all these into LESS mixins enjoy : https://github.com/aliencreations/responsiveless

Reply

170.

Diogo

Permalink to comment# September 16, 2015

If any one have doubts and windows sizes etc Place this JavaScript alert to kwon all informations
about window sizes(width and height) and device pixel ratio to help to develop better your
mediaqueries. Thank You

JavaScript code:

alert(
Device PixelRatio: + window.devicePixelRatio +
\nDevice Width: + window.innerWidth +
\nDevice Height: + window.innerHeight
);

*NOTE: \n its equal to break line, btw :)

Reply

171.

TB

Permalink to comment# October 12, 2015


There are duplicate queries for ipad mini and ipad 1-2 which is a bit confusing.

Reply

172.

Chip

Permalink to comment# October 24, 2015

I am making a website but dont know which pixel values to put in my CSS. What would you suggest be
the three most basic width ranges?
For example:

@media screen
and (min-device-width: ???px;)
and (max-device-width: ???px;)

Reply

Hkan Olsson

Permalink to comment# October 29, 2015

Hey Chip

Save yourself from lots of trouble dont use device-width. Its a waste of time. Why? Because
different devices report differently. This means the result will be random thus useless.

I have done several tests with many devices. If folk used solely iPads and iPhones it would
work. However on the Android side its inconsistent. So, you cant control what you want to
control.

(You can read more details about this about 7 posts up)

Cheers
173.

Trevor

Permalink to comment# November 24, 2015

Using device specific viewports is not very forward thinking. I agree with the ideas in this article:
https://responsivedesign.is/articles/why-you-dont-need-device-specific-breakpoints

Reply

nate

Permalink to comment# January 6, 2016

I just want to know how to set up media queries to work with the majority of devices. Device-
specific is not the route Id like to go because there are an insane amount of devices, but I still
want to know the basic media query breakpoints that I should use and best practices for doing
so. Any tips?

174.

Troy

Permalink to comment# January 6, 2016

Awesomethis is exactly what I was looking for.

Reply

175.

Anurag
Permalink to comment# January 13, 2016

Whats the difference between min width and min device width?

Web designing training

Reply

176.

Appso

Permalink to comment# February 8, 2016

I need media query for windows Microsoft/Nokia lumia 520 and above.

Please help me.

Reply

177.

Bruno Amaral

Permalink to comment# May 13, 2016

Are the queries updated?

Post says it hasnt been updated since 2010

Reply

178.

Maruthi

Permalink to comment# June 16, 2016

Awesome! This helped me a lot.


Reply

179.

gad

Permalink to comment# July 29, 2016

Wow is great your tutorial to understand better the term media for the mobiles, this my responsive for
my two sites:

/* MENU */

@media (max-width: 820px) {

#plus-haut {display:none}
.haut_bloc{display:none}
#reseaux{display:none}

.bloc_responsive{

/* background-color:#15497d; */
background-color:#67aabf;
background-repeat:repeat;
width:100%;
height:100%;
}

.haut_bloc_responsive {
padding-left:0px;
text-align:center;
left:0px;
}

.haut_bloc_responsive img{
margin-top:20px;
margin-top:10px;
}

.haut_bloc_responsive li {
list-style:none;
font-family:'font-h2';
font-size:20px;
}

#tel-mobile {
font-size:30px;
line-height:20px;
font-weight: bold;
color : white;
width:110%;
margin-top:20px;
}

#title-header-mobile{
font-size:20px;
line-height:40px;
font-weight: bold;
color : white;
}

.menu-responsive {
font-size:18px;
font-family:'font-h2';
color:#FFFFFF;
margin-top: 2px;
margin-left: 0px;
padding-left:5px;
margin-bottom:0px;
display: inline-block;
text-align:left;
}
.menu-responsive2 {
text-decoration:none;
font-size:22px;
font-family:'font-h2';
margin-top: 0px;
margin-left: 10px;
margin-right:40px;
padding:0px; !important margin-bottom:0px;
display: inline-block;
float:right;

.menu-responsive2 a:link, a:hover, a:active, a:visited {


background-color:none; !important
color:#FFFFFF; !important
text-decoration:none;
border-bottom:0px; !important
}

.menu-responsive-titre li{
font-size:17px;
font-family:font-h2;
text-align:center;
}

@media (min-width: 820px)


{
.haut_bloc_responsive {
display:none;
}

.bloc_responsive{
display:none;
}

#fond {

/* background-color:#15497d; */
background-color:#67aabf;
background-repeat:repeat;
min-width:1020px;
}

http://plombier-sos.com/ and http://serrurier-paris-urgent.com/

If you have something to improve in my code CCS please let me to know , thank you and please feel
free to help to improve this code

Reply

180.

Vuken Diesel

Permalink to comment# August 30, 2016

This is very cool how you list every single devices. While is it very useful, it can be very daunting and
overwhelming.
I usually use 4 ranges for my site that it.
1)smallest for wearable,
2)smaller for mobile phone,
3)medium for the tablet, and
4)large to max for laptop and desktop.

Thank you again for the detailed list. That is a lot of work and I bow to you sir. Thank you again for
awesome works on this site. I learned a lot from this site.

Reply

181.

Jayesh patel

Permalink to comment# September 15, 2016

http://eighttech.com/projects/8com/vpage.html

Please give issues in this URL


I have some issues in iphone and I have no iPhone device
Please helps

Reply

182.

Julio V.

Permalink to comment# November 15, 2016

Hi,

You have wrong device-width for Nexus 7, its 960px not 906px.

Reply

183.

Nate
Permalink to comment# December 10, 2016

Can you please explain why you used a media query like this? @media (max-width: 48.75em)

Reply

184.

Shafeequrrahman Khan

Permalink to comment# December 19, 2016

Hi,

I want to know, how many type of media screen size.


Please help me anyone !!!!!!!!

Reply

185.

Siddharth

Permalink to comment# January 7, 2017

I wrote a mini library about it, i hope i will develop it more, have a look

Reply

186.

Sunny

Permalink to comment# February 8, 2017

In the above post, I see the CSS script up to Iphone 4 to Iphone 6/6 Plus. Looking forward the
Resolution ( min and max size) for IPHONE 7 & 7 plus. Could you please share the details.

/* iPhone 6+ */
/* Portrait and Landscape */
@media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3) {

/* Portrait */
@media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: portrait) {

/* Landscape */
@media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: landscape) {

Reply

187.

Alex Brown

Permalink to comment# February 23, 2017

If you think responsives simple, I feel bad for you son. We got 99 viewports, but the iPhones just one.
Josh Brewer, March 10, 2010

Love that quote, mind if I use it on my site?

Reply

188.
User

Permalink to comment# April 26, 2017

Using device-height and device-width, respectively min/max-device-height and min/max-device-


width is deprecated per MDN https://developer.mozilla.org/en-
US/docs/Web/CSS/Media_Queries/Using_media_queries and should not be used any more.

Reply

189.

Nate

Permalink to comment# April 26, 2017

It seems like all you really have to do now is design your website to break wherever it looks good using
a desktop computer and Chrome web inspector tools.

Whatever the heck happens with retina and other high pixel density displays doesnt seem to matter
since apparently they make their higher amount of pixels display as if its the same amount of pixels as
a regular display.

Based on this, 768px still seems a reasonable breakpoint for tablets and 480px and 320px seems to be a
reasonable breakpoint for phones. Whether those dimensions are actually 1.5x, 2x, 3x or higher on
retina-like displays doesnt seem to matter as far as media queries are concerned.

Reply

190.

Simon Robertson

Permalink to comment# June 8, 2017

Personal opinion here of course, but your website really shouldnt care what device it is running on. CSS
media queries should be used to adjust the website layout, and possibly visual style, to provide the best
user experience possible for the device screen resolution (viewport size). Break points, if thats your
thing, can be determined based on the height of the viewport at runtime (100% HTML element height,
or a calc() derived from it, etc).
If you really need to provide device-specific content, using JavaScript or a server-side script to query the
user agent string is one solution, but it isnt super reliable due to the fact the user agent string can be
easily changed.

Design for the viewport, not for the device :)

Reply

Submit a Comment

Name*
Email

Comment

4.1

Copy and paste this code: micuno *

Get the CSS-Tricks newsletter

Submit Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like
`<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and
after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like
writing a letter to the editor. All submitted comments will be read, but not all published. Published comments
will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

Front-End Jobs
National Geographic Partners is hiring a Senior Creative Developer

Oregon State University Extended Campus is hiring a Web Developer

Printerpix is hiring a Front End Web developer

See More Jobs Post a Job

Drag and drop builder. Spam protection. Logic and branching. Report building. API access and
integration. Easily create powerful web forms with Wufoo.

We've been using Wufoo for over a decade here at CSS-Tricks.

Subscribe

Email Address

Lots of great stuff that isn't published anywhere else!

CSS-Tricks web host since day one. Save 20% with code CSSTRICKS.

CSS-Tricks* is created, written by, and maintained by Chris Coyier and a team of swell people. It is built
on WordPress, hosted by Media Temple, and the assets are served by MaxCDN. It is made possible
through sponsorships from products and services we like.

*May or may not contain any actual "CSS" or "Tricks".

Contact About Archives Advertise Jobs License Subscribe RSS Guest Posting

Das könnte Ihnen auch gefallen