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?
wow :D
@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.
try browserStack http://www.browserstack.com/user/dashboard
@Tim If you’re using a Mac get yourself: Xcode which has IOS Simulator (iPhone and iPad). Here’s a quick movie to help you get it. http://www.youtube.com/watch?v=oobXPWHx3ZI
Then head over to http://moduscreate.com/enable-remote-web-inspector-in-ios-6/ to enable developer mode in Safari.
Combine the two and works like element inspector in most browsers, just for iPhone and iPad :)
Haven’t tested this on Windows Safari – anyone else know?
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
Tested it on the ipad 3, works fine
(this one worked:
@media only screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-min-device-pixel-ratio: 1)
{
#background img {
display: none;
}
}
)
@SirKay
you so cool! that code u’ve give is work 100%. thanks.
I have a related question. The answer might involve using the media query described in this post (or something else). If your page content is less than 1024px in height, is there a technique to make the footer adjust so that the footer background (color or image-repeat) goes all the way down to the bottom of the page when it is viewed in portrait on the ipad? I assume this is a standard problem but I haven’t seen any solutions for it. I’m thinking the footer is the most obvious div to adjust, but there could be some other technique or div that “saves” the design in this use case. Any suggestions would be greatly appreciated.
Should I use
plus
@media only screen and (device-width: 768px)
{
#background img {
display: none;
}
/* Your iPad specific rules here */
}
or could I do without this code?
for some reason this code meta name=”viewport” content=”width=device-width” didn’t appear in the blank areas above
Wow! been searching for days how to fix this issue, now everything works on ipad without messing up the site in other browsers.
Realy thank you for this post!
Has anyone tested these code tips on the new larger Samsung phones?
Thanks guys, for those want to use it inside JavaScript
if (window.matchMedia(‘only screen and (device-width: 768px)’).matches)
{
// ipad… maybe run some small-screen related dom scripting?
}
if (window.matchMedia(‘only screen and (max-width: 480px)’).matches)
{
// smartphone/iphone… maybe run some small-screen related dom scripting?
}
Wow, I never new this. This is awesome stuff. Thanks for sharing it ;)
Perfect. Saved me a lot of trouble in a project short before going live!
Safari has been discontinued on Windows and the remote inspection stuff is only in version 6+ (which is not available for Windows).
Any Idea how to design a div.scroll to show the scroll bar on the ipad. Currently this CSS trick does work with a two figure scroll , which is fine with me. I really want the scroll bar to be visible on the Ipad so the user knows that their is content to be scrolled through?? Any help would be greatly Awesome!
Strangely this didnt work for me, at all.
Kept digging and found a way that did, hop this helps someone:
@media screen and (max-width:480px) {
/* Making the headings red for smartphone users */
h1 {
color: red;
}
}
@media screen and (min-width:481px) and (max-width:1280px) {
/* Making the headings Black targeting PC Users */
h1 {
color:green;
}
}
@media screen and (min-width:1281px) {
/* Making the headings red for smartphone users */
h1 {
color: black;
}
}
thanks for quick and easy way :)
sorted the issue I was having.
why would the device-width = 768? Why doesn’t it equal 1024?