IE7 on XP render the media=“print” stylesheets

走远了吗. 提交于 2019-12-25 07:16:25

问题


In my web page, I'm using 2 stylesheets :

<link rel="stylesheet" href="css/screen-layout.css" media="screen" type="text/css" />
<link rel="stylesheet" href="css/print-layout.css" media="print" type="text/css" />

inside print-layout.css there is :

.ui-dialog * {display: none !important;}

When I viewed my webpage on IE7, it's supposed to ignore the media="print" one, but it didn't, it applied the display: none, causing all the elements to be hidden. And in the debugbar plugin for IE7, I can see that IE7 applied the print-layout.css file. How is that possible? or am I missing any requirements for using print on IE7?

Thanks :)


回答1:


That syntax works even on IE7 but if you need to exclude that browser from applying your print style, just rewrite your last inclusion in this way:

<style type="text/css" rel="stylesheet">
   @import url('css/print-layout.css') print;
</style>

since IE7 hasn't implemented the media type on @import rule.

Otherwise just wrap the second inclusion in a conditional comment, like so

<!--[if (gte IE 8)]><!-->
   <link rel="stylesheet"... media="print" /> 
<!--<![endif]-->

so you include the print style for all browser except IE < 8.


As a side note: IE7 usage is globally < 1%:
see http://gs.statcounter.com/#browser_version-ww-monthly-201211-201304



来源:https://stackoverflow.com/questions/16333764/ie7-on-xp-render-the-media-print-stylesheets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!