CSS 媒体类型:如何为移动设备加载 CSS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1248756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:56:08  来源:igfitidea点击:

CSS media type: How to load CSS for mobile?

cssmobileopera-minimedia-type

提问by Andrea Ambu

With this code:

使用此代码:

<link rel="stylesheet"
      type="text/css"
      href="media/css/mobile.css"
      media="handheld" />
<link rel="stylesheet"
      type="text/css"
      href="media/css/screen.css"
      media="screen" />

on my N78the nokia's default browser and opera mini load screen.cssinstead of mobile.css.
What am I missing?

在我的N78 上,诺基亚的默认浏览器和 Opera mini 加载screen.css而不是mobile.css
我错过了什么?

回答by dalizard

Nokia N78 uses the S60 browser, which reads only "screen" stylesheets. It won't read the "handheld". It doesn't support media query. Instead of trying to type everything here, have a look at this article and you will solve the problem - http://www.alistapart.com/articles/return-of-the-mobile-stylesheet

诺基亚 N78 使用 S60 浏览器,它只读取“屏幕”样式表。它不会读取“手持设备”。它不支持媒体查询。与其尝试在此处输入所有内容,不如查看本文,您将解决问题 - http://www.alistapart.com/articles/return-of-the-mobile-stylesheet

回答by Ryan Florence

Using the iPhone as an example:

以 iPhone 为例:

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

I have no idea which browsers/devices this does and does not work for. The only mobile device I've developed for is the iPhone. But I'm sure you can give it a shot with your nokia.

我不知道这对哪些浏览器/设备有效,哪些无效。我开发的唯一移动设备是 iPhone。但我相信你可以用你的诺基亚试一试。

More on media queries

更多关于媒体查询

回答by Gerald Senarclens de Grancy

Opera Mini uses the media type screen because it fits its behavior and capabilities best. However, it will use handheld stylesheets if you switch to mobile view mode. See A developer's look at Opera Mini 5 beta 2for more information.

Opera Mini 使用媒体类型屏幕,因为它最适合其行为和功能。但是,如果您切换到移动视图模式,它将使用手持样式表。有关详细信息,请参阅开发人员对 Opera Mini 5 beta 2 的看法