简体   繁体   English

IE条件注释不起作用

[英]IE conditional comments are not working

I have style_desktop.css for all the desktop and another style_mobile.css for mobile device. 我对所有的台式机和另一style_mobile.css移动设备style_desktop.css。

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

<link rel="stylesheet" media="screen and (min-device-width:781px)" type="text/css"
      href="style_desktop.css"/>
<link media="only screen and (max-device-width: 780px) and (min-device-width: 320px)"
      href="style_mobile.css" type="text/css" rel="stylesheet"/>

The above code works fine except IE 8 and below. 上面的代码工作正常,但IE 8及以下版本除外。 I suppose it is because IE 8 and below does not recognize "(min-device-width:781px)" 我想这是因为IE 8及以下版本无法识别“(min-device-width:781px)”

So I updated the code as below but it is still not working. 因此,我更新了如下代码,但仍无法正常工作。

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

<link rel="stylesheet" media="screen and (min-device-width:781px)" type="text/css"
      href="style_desktop.css"/>
<link media="only screen and (max-device-width: 780px) and (min-device-width: 320px)"
      href="style_mobile.css" type="text/css" rel="stylesheet"/>
 <!--[if lt IE 9]>
      <link rel="stylesheet" type="text/css" href="style_desktop.css"/>
 <![endif]-->

If it is any desktop browser than I want style_desktop.css to be linked. 如果它是任何桌面浏览器,我都希望链接style_desktop.css
If it is any mobile browser than I want style_mobile.css to be linked. 如果它是任何移动浏览器,我都希望链接style_mobile.css

By testing I found that the conditional comments are not working. 通过测试,我发现条件注释不起作用。

Edit: 编辑:
I am using wordpress if it makes any difference. 我正在使用wordpress,如果有什么不同。 I have removed the get_template_directory_uri(); 我删除了get_template_directory_uri(); from the href just for the sake of clarity. href只是为了清楚起见。

You can try to enabling HTML5 and CSS3 for older IE: 您可以尝试为较旧的IE启用HTML5和CSS3:

<!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<![endif]-->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM