特定于浏览器的移动浏览器CSS

时间:2011-07-31 01:22:31

标签: android css firefox mobile opera

如何在Android上为不同的移动浏览器(如Opera Mobile和Firefox)进行媒体查询?当我使用某些浏览器时,CSS确实会中断。

1 个答案:

答案 0 :(得分:4)

您不能直接使用CSS,但可以使用

// target mobile devices
@media only screen and (max-device-width: 480px) {
    body { max-width: 100%; }
}

// recent Webkit-specific media query to target the iPhone 4's high-resolution Retina display
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
    // CSS goes here
}

// should technically achieve a similar result to the above query,
// targeting based on screen resolution (the iPhone 4 has 326 ppi/dpi)
@media only screen and (min-resolution: 300dpi) {
    // CSS goes here
}

您也可以在HTML中定义

<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="css/mobile.css" type="text/css" />
<link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)" href="css/mobile.css" type="text/css" />
<link rel="stylesheet" media="only screen and (min-resolution: 300dpi)" href="css/mobile.css" type="text/css" />
相关问题