IE 忽略样式表中的 @media
在我的样式表中,我有这 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;}
我该如何解决这个问题? 是否有我可以添加的 hack、脚本、插件以使其在 IE 中工作? 谢谢
At the biginning of my stylesheet, I have those 3 lines that adjust the font-size depending of the sreen resolution. It work perfectly in all browsers except IE (I tested 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;}
how can i resolve this problem?
Is there an hack, script, pluggin i can add to make it work in IE ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
IE 8 及更低版本不理解媒体查询。您可以在 HTML 中使用注释使样式表仅对 IE 可见。
请参阅此页面以获取说明:http://css-tricks.com/how- to-create-an-ie-only-stylesheet/
例如:
在下面的示例中,媒体查询为宽度不超过 480 像素的屏幕提供一个样式表,为宽度为 481 像素或更大的屏幕提供另一个样式表。它为 IE 8 或更低版本的用户提供相同的样式表:
IE 8 and below don't understand media queries. You can use a comment in your HTML to make a stylesheet visible to only IE.
See this page for an explanation: http://css-tricks.com/how-to-create-an-ie-only-stylesheet/
Eg:
In the below example, a media query serves one stylesheet to screens up to 480px wide, and another for screens 481 or larger. It serves the same stylesheet to users of IE 8 or below:
Internet Explorer 在 IE9 之前不支持它们。
Scott Hanselman 有一个关于媒体查询和渐进增强的精彩故事。
http://www.hanselman.com/blog/LearningAboutProgressiveEnhancementSupportingMobileBrowsersWithCSS3MediaQueries.aspx
Internet Explorer does not support them till IE9.
Scott Hanselman has a nice story about media queries and progressive enhancement.
http://www.hanselman.com/blog/LearningAboutProgressiveEnhancementSupportingMobileBrowsersWithCSS3MediaQueries.aspx
当然它会忽略它们,直到 IE9,才支持媒体查询。
Of course it ignores them, until IE9, no media queries support is there.
如果您正在寻找 jQuery 解决方案来解决旧版 IE 浏览器的此问题,这里是一个很好的资源。
http://www.protofunc.com/scripts/jquery/mediaqueries/
希望如此帮助
If you're looking for a jQuery solution to solve this problem with older browsers of IE, here is a good resource.
http://www.protofunc.com/scripts/jquery/mediaqueries/
hope this helps
当然,请看一下《回应》。我已经使用它几次来将此功能扩展到旧版 IE。
https://github.com/scottjehl/Respond
Sure, take a look at Respond. I've used it a couple of times to extend this functionality to the older IEs.
https://github.com/scottjehl/Respond