检测并链接 iphone 3 和 iphone 4 的不同样式表

发布于 2024-12-02 07:49:52 字数 468 浏览 4 评论 0原文

我试图通过这种方式为 iphone 3 和 iphone 4 定义不同的样式表

<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" media="all and (max-device-width: 320px)" href="iphone3.css" />
<link rel="stylesheet" media="all and (max-device-width: 640px)" href="iphone4.css" />

,并且 iphone3.css 和 iphone4.css 都有一个 body{display:none;} 来测试它们是否正常工作,但在我的 iphone4 中我仍然可以看到网站,

我错过了什么?

谢谢!

I am trying to define different stylesheets for iphone 3 and iphone 4 this way

<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" media="all and (max-device-width: 320px)" href="iphone3.css" />
<link rel="stylesheet" media="all and (max-device-width: 640px)" href="iphone4.css" />

and both iphone3.css and iphone4.css have a body{display:none;} to test that they are working but in my iphone4 I still see the webiste,

what am I missing?

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半仙 2024-12-09 07:49:52

这将同时针对 iPhone 3 和 4:

@media only screen and (max-device-width: 480px){
    body{background:red;}
}

或者

<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone3.css" />

您可以使用此查询覆盖以前的样式并仅针对 iPhone 4:

@media only screen and (-webkit-min-device-pixel-ratio: 2){
    body{background:blue;}
}

或者

<link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)" href="iphone4.css" />

This will target both iPhone 3 and 4:

@media only screen and (max-device-width: 480px){
    body{background:red;}
}

or

<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone3.css" />

You can use this query to then override the previous styles and target only iPhone 4:

@media only screen and (-webkit-min-device-pixel-ratio: 2){
    body{background:blue;}
}

or

<link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)" href="iphone4.css" />
日暮斜阳 2024-12-09 07:49:52
@media only screen and (max-width: 480px){
    body{background:red;}
}
@media only screen and (max-width: 480px){
    body{background:red;}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文