css - IE 忽略样式表中的@media

标签 css media-queries

在我的样式表开始时,我有 3 行根据屏幕分辨率调整字体大小。它在除 IE 之外的所有浏览器中都能完美运行(我测试了 IE7-8)。

@media screen and (min-width: 0px) and (max-width: 1199px){html, body{font-size:8px;}}
@media screen and (min-width: 1200px) and (max-width: 1499px){html, body{font-size:9.5px;}}
@media screen and (min-width: 1500px){html, body{font-size:11px;} 

我该如何解决这个问题? 我可以添加黑客、脚本、插件以使其在 IE 中工作吗? 谢谢

最佳答案

IE 8 及以下版本不理解媒体查询。您可以在 HTML 中使用注释使样式表仅对 IE 可见。 请参阅此页面以获取解释:http://css-tricks.com/how-to-create-an-ie-only-stylesheet/

例如:

<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<![endif]-->

在下面的示例中,媒体查询为一个样式表提供最大 480 像素宽的屏幕,另一个为 481 或更大的屏幕提供样式表。它为 IE 8 或更低版本的用户提供相同的样式表:

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

<link
    rel="stylesheet"
    type="text/css"
    media="screen and (min-device-width: 481px)" href="/css/style.css"/>   

<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<![endif]-->

关于css - IE 忽略样式表中的@media,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7234798/

相关文章:

python - 如何提取其中包含特定元素的所有 div,它不是 class、span、a 或 li?

css - 为什么我的一半 <hr> 的样式与其他的不同?

java - 如何将 java 程序嵌入我的网站?

css - IE8 忽略带有 respond.js 的媒体查询

asp.net - 移动 View 上的堆栈控件

javascript - 如何在 CCS 媒体查询中重新定位事物

css - 是否可以用 CSS 中的图像替换 HTML 图像?

javascript - JQuery:窗口调整大小的更改宽度始终变为 0

html - 媒体查询 div 不改变宽度,但其他一切正常

css - 我可以使用媒体查询来检测设备是否可以调用电话吗?