Code Snippet
iPad-Specific CSS
@media only screen and (device-width: 768px) {
/* For general iPad layouts */
}
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
/* For portrait layouts only */
}
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
/* For landscape layouts only */
}
No Biggie. But you’re missing a closing slash on your second comment line.
Thanks!
I’d love to see a screencast on designing for an iPad
i’m sure it’s like the iPhone one you made but still…
This CSS will also be used by *all small screens* – this might be undesirable since often the CSS issues (such as position fixed) may not apply to netbooks for instance where the browser and os may be different to an ipad….
I’m wondering, why would the device-width = 768? Why doesn’t it equal 1024?
1024px is the longest side, 768px is the shortest side, therefore you want to make sure the CSS will work on the iPad’s shortest side too. It is iPad specific.
The min width 481px to max width 1024px is so the CSS works in the set orientation on any device between the pixel widths iPhone and iPad in this case.
Hope that helps.
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
/* For portrait layouts only */
}
is going to give you some problems with newer Android devices. Found that in order for Portrait styles for iPad not being getting picked up by my Galaxy S2 device was to use:
@media only screen and (device-width: 768px) {
}
Instead.. I know its not really a solution, but it needs to be noted.
This code doesn’t seem to do anything for me.. what am I doing wrong?
@designer: Try doing this: #page @media only screen and …. { .. }
Is there anyway to test the css if you don’t have an iPad? Something like IE tester for Mobile? Tried http://ipadpeek.com/ but it doesn’t apply the styles.
Thanks for the tip on the snippet code, I did not realize tha it was this easy. :-)
For those of you who are trying to get the above code to work on ipadpeek.com, there are a few things you need to do first.
1. insert the following meta tag at the top of the html page just below the opening tag.
2. When you are ready to view your site, you will have to change the monitor resolution to 1024×768 and refresh the ipadpeek.com web browser page.
Sorry for the double post, but the tag code did not show in the above post.
here is the meta tag I was refering to.
<meta name="viewport" content="width=device-width" />
@media only screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-min-device-pixel-ratio: 1)
{
/* Your iPad specific rules here */
}
@media only screen and (device-width: 768px)
{
#background img {
display: none;
}
/* Your iPad specific rules here */
}
Wow, quick and easy fix! Thanks for sharing this technique, it saved me a huge headache.
Thanks!
What about ipad 3, that has a higher definition than 768px
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.