3 media queries for iphone portrait, landscape and ipad portrait

邮差的信 提交于 2019-12-31 09:46:49

问题


I have tried the different combinations of width & device-width but on the iPhone in landscape this code never turns the background red;

I am having problem when I have more than 1 media query. See this JSfiddle example the div background is never green unless you remove the last media query

This is what I would like 3 different media queries which target:

  1. both smartphones and tablets(portrait only). This will be where I have all my generic styles for responsive layout
  2. width: 320px - 479px - this will apply to small screens, such as iphone in portrait only
  3. width: 480px - 640px - this will apply to larger screens such as iphone in landscape and ipad in portrait. Not ipad in landscape.

Note this is for a HTML email so its not possible to use JS.

@media only screen and (max-width: 640px) {
    body { padding: 10px !important }
}
/* Small screen */
@media only screen and (min-device-width: 320px) and (max-device-width: 479px) {
    body { background: blue !important }
}
/* iPhone landscape and iPad portrait */
@media only screen and (max-device-width: 480px) and (max-device-width: 640px) {
    body { 
       background: red !important 
       -webkit-text-size-adjust:none; 
    }
}

Reference: http://css-tricks.com/snippets/css/media-queries-for-standard-devices/


回答1:


Your own attempt modified

@media only screen and (max-width: 640px) and (orientation: portrait) {
    body { padding: 10px !important }
}

/* Small screen */
@media only screen and (min-device-width: 320px) and (max-device-width: 479px) and (orientation: portrait) {
    body { background: blue !important }
}

/* iPhone landscape and iPad portrait */
@media only screen and (max-device-width: 480px) and (orientation: landscape),
@media only screen and (max-device-width: 640px) and (orientation: portrait)  {
    body { 
       background: red !important 
       -webkit-text-size-adjust:none; 
    }
}



回答2:


Media queries also support device orientation. You should try that

@media screen and (orientation:portrait) {
    /* Portrait styles */
}

@media screen and (orientation:landscape) {
    /* Landscape styles */
}

You can also combine them with width like so

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

}



回答3:


Take a look at this resource, will give you media queries for pretty much everything http://arcsec.ca/media-query-builder/ , you need to be be specifying a min width aswell. also less of the !important, dirty :)

in your case

@media only all and (min-device-width: 320px) and (max-device-width: 480px) {
/* insert styles here */
}



回答4:


Responsive emails can be tough because there are so many e-mail clients out there, and support can be limited for media queries. You may just want to look into making your divs fluid with percentages, so they scale, rather than media queries. The people at zurb have some great templates which may help out too. http://www.zurb.com/playground/responsive-email-templates

Hope that helps.




回答5:


i tried this by using Om's solution in a diff. way it worked for me, hope it helps someone

@media only screen and (max-device-width:1024px) and (orientation: portrait)     {
    /*style*/    
    }
@media only screen and (max-device-width: 1024px) and (orientation: landscape)  {
    /*style*/
}


来源:https://stackoverflow.com/questions/13910255/3-media-queries-for-iphone-portrait-landscape-and-ipad-portrait

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!