2012-07-27 107 views
0

正在開發一個項目,我需要使用媒體查詢區分iPhone,iPad的橫向和縱向模式。另外,我正在使用iPad 3,iPhone 4s。 儘管聽起來很簡單明瞭,但我最難得到這個工作。 我到最接近的是這樣的: -使用媒體查詢檢測iPad/iPhone

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

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

@media (max-device-width: 480px) 
and (orientation: portrait) { 
/*iPhone portrait*/ 
} 

@media (max-device-width: 480px) 
and (orientation: landscape) { 
/*iPhone landscape*/ 
} 

但是,這並不對iPhone的肖像/風景模式之間進行區分。 任何可能出錯的線索?

回答

1

下面是一些示例代碼,演示了iPhone上的功能查詢。它在肖像中是白色的,在景觀中是黑色的。你可以忽略的base64一部分,只是爲了無需外部文件提供一個圖標:

<!DOCTYPE html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="apple-mobile-web-app-capable" content="yes" /> 
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
<link rel="apple-touch-icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADkAAAA5CAYAAACMGIOFAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2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o2exbFPkc+ToN6lsq+mkS17XK/Zp1nd60YHU1YL4Tn3tSp3rZNjgmMGqhFoYajHOVMp0TyYV82uqiplal1HetGFWt/+870IaZrjqbN6FbBMieRcNqhgJcnqmNVV26pqyr3r5HKkG5Qws6ZiUCqmjkiJlDFsaJiCSqHBEwktgotGItmaZtKlRj57PYIkY5eKJahojmq+PIH1VBjk916zx2oIuF6tND4XtiLQNBArcRIx9IgSkUQzKA92GTqBhpQ0jXNLjZ9tmsjqMrncPEhYMRO5vvVKkjlEkNSXWqIewmIGmcB5fUbbvdlqzHGJtqpxKthSJuPBc7qAlNW0hUke027uOndtSlR/QQDN0qRGW1YP3xxeci/Fm9UUr8ygUSeLmwi9NNguiquEsUz1OFdaDR64eBBMbeLCU+cqk90aHY9Qh+lNE4SON0m18rZhwNAqMJ97VX8qUR9fSz9NM+jS5c8YYjkMHiaX3VIjJWxLCR0jj1S9hDfZ+VRa6hUpIF3u4s2T/xWvSxduN9ExFmkXmsJMdcw+12/9/wEA9H8R00XjMG0AAAAASUVORK5CYII="/> 
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> 
<title>Media</title> 
<style> 
html,body{width:100%;height:100%;margin:0;padding:0;} 
@media screen and (max-device-width: 320px) and (orientation:portrait) { 
    body { background-color:#FFF; } 
} 
@media screen and (max-device-width: 320px) and (orientation:landscape) { 
    body { background-color:#000; } 
} 
</style> 
</head> 
<body onload="fullscreen()"> 
<span style="color:#000">Portrait</span><span style="color:#FFF">Landscape</span> 
</body> 
</html> 
+0

原來方向媒體查詢的iPhone手機無法正常工作,並且只能用於解鎖iPhone和iPad的作品找到這個,剛剛發現這一點,並一直在尋找一些替代的方法來解決這個 – sanz 2012-07-27 01:17:52

+0

我不確定你在哪裏確定,它絕對適用於我的項目。我將修剪一個例子,併發布一些示例代碼 – 2012-07-27 01:26:30

+0

發佈樣本代碼 – 2012-07-27 01:50:47

1

我用下面的媒體查詢(定義爲Web應用程序飛濺圖像)。它可以處理iPhone非視網膜和iPhone 4/4以及非視網膜iPad和視網膜iPad(縱向和橫向)。您可以在https://github.com/gwilson/iOSWebAppTemplates

<!-- iPhone standard resolution 320x460 (landscape not needed because all web apps start portrait on iPhone) --> 
<link rel="apple-touch-startup-image" href="splash-320x460.jpg" media="(device-width: 320px)" /> 
<!-- iPhone high resolution (retina) 640x920 pixels (landscape not needed because all web apps start portrait on iPhone) --> 
<link rel="apple-touch-startup-image" href="splash-640x920.jpg" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" /> 
<!-- iPad Portrait 768x1004 --> 
<link rel="apple-touch-startup-image" href="splash-768x1004.jpg" media="(device-width: 768px) and (orientation: portrait)" /> 
<!-- iPad Landscape 748x1024 (yes, a portrait image but with content rotated 90 degrees - allows 20px for status bar) --> 
<link rel="apple-touch-startup-image" href="splash-748x1024.jpg" media="(device-width: 768px) and (orientation: landscape)" /> 
<!-- iPad retina Portrait 1536x2008 --> 
<link rel="apple-touch-startup-image" href="splash-1536x2008.jpg" media="(device-width: 768px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" /> 
<!-- iPad retina Landscape 1496x2048 (yes, a portrait image but with content rotated 90 degrees - allows 40px for status bar) --> 
<link rel="apple-touch-startup-image" href="splash-1496x2048.jpg" media="(device-width: 768px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" /> 
0
<html> 
<head> 
<style type="text/css"> 

/* Mobile Layout: 480px and below. */ 
.gridContainer { 
    margin-left: auto; 
    margin-right: auto; 
    width: 100%; 
    padding: 0; 
    height: 300px; 
    background: #ff0000; 
} 
#LayoutDiv1 { 
    clear: both; 
    float: left; 
    margin-left: 0; 
    width: 100%; 
    display: block; 
} 

/* Tablet Layout: 481px to 768px. Inherits styles from: Mobile Layout. */ 
@media only screen and (min-width: 481px) { 
.gridContainer { 
    width: 80.675%; 
    padding-left: 1.1625%; 
    padding-right: 1.1625%; 
    background: #00ff00; 
    height: 200px; 
} 
#LayoutDiv1 { 
    clear: both; 
    float: left; 
    margin-left: 0; 
    width: 100%; 
    display: block; 
} 
} 

/* Desktop Layout: 769px to a max of 1232px. Inherits styles from: Mobile Layout and Tablet Layout. */ 
@media only screen and (min-width: 769px) { 
.gridContainer { 
    width: 88.2%; 
    max-width: 1232px; 
    padding-left: 0.9%; 
    padding-right: 0.9%; 
    margin: auto; 
    background: yellow; 
    height: 100px; 
} 
#LayoutDiv1 { 
    clear: both; 
    float: left; 
    margin-left: 0; 
    width: 100%; 
    display: block; 
} 
} 
</style> 
</head> 

<body> 
<div id="LayoutDiv1"> 
    <div class="gridContainer">Welcome to iPad</div> 
</div> 
</body> 
</html>