2012-07-04 47 views
0

我一直在使用確定是否iPhone Safari瀏覽器是垂直視模式CSS

@media screen and (max-width: 480px) 

,以確定如果用於觀看的設備是iPhone,但是,看來這個規則適用於垂直和水平視口模式。

如何確定視口是否確實是垂直的(即較小寬度的視口)?我已經嘗試

@media screen and (max-width: 320px) 

但它似乎並沒有註冊。

此外,位於(max-width: 480px)限制下的所有樣式也適用於垂直模式。

回答

3

可以使用orintation媒體查詢:

/* Portrait */ 
@media screen and (orientation:portrait) { 
    /* Portrait styles */ 
} 
/* Landscape */ 
@media screen and (orientation:landscape) { 
    /* Landscape styles */ 
} 
+1

張貼的問題後,我偶然偶然發現了這一點:http://css-tricks.com/snippets/css/media-queries爲標準設備/它似乎有伎倆。我的最後一個查詢看起來像這樣的肖像:'@media only screen and(max-width:320px)'看起來'只'是這裏必需的關鍵字。 –

0

我知道你想做到這一點CSS,但CSS真的不是檢測iPhone的方式......你應該使用JavaScript。

,這將幫助您檢測在JavaScript中定位:

function detectOrientation() { 
if (orientation == 0) { 
document.className = 'portrait'; 
} 
else if (orientation == 90) { 
document.className = 'landscape'; 
} 
else if (orientation == -90) { 
document.className = 'landscape'; 
} 
else if (orientation == 180) { 
document.className = 'portrait'; 
} 
} 
相關問題