Using two conditional css if statements uses neither style sheet

有些话、适合烂在心里 提交于 2019-12-12 01:34:06

问题


At my wit's end here. Trying to implement two different style sheets, one for IE and one for when it's not IE. In every example I've ever seen this is exactly the way you're supposed to do this. Can anyone spot any mistakes in this? Seems like it should be simple enough.

<!--[if !IE]><link rel='stylesheet' type='text/css' href='/login/css/correctlogin.css'/><![endif]-->
<!--[if IE]><link rel='stylesheet' type='text/css' href='/login/css/ielogin.css'/><![endif]-->

回答1:


For the !IE conditional comment, the correct format is <!--[IF !IE]>--> ... <!-- <![endif]-->, because non-IE browsers do not have a special treatment for the conditional comments.

<!--[if !IE]> --><link rel='stylesheet' type='text/css' href='/login/css/correctlogin.css'/><!-- <![endif]-->
<!--[if IE]><link rel='stylesheet' type='text/css' href='/login/css/ielogin.css'/><![endif]-->

See also: http://www.quirksmode.org/css/condcom.html
PS. Conditional comments are not supported in IE10 any more.




回答2:


The if not IE statement is redundant. All you need is an if IE statement.

<link rel='stylesheet' type='text/css' href='/login/css/correctlogin.css'/>
<!--[if IE]>
<link rel='stylesheet' type='text/css' href='/login/css/ielogin.css'/>
<![endif]-->

This tells every browser to use correctlogin.css and if the browser is IE, THEN also use ielogin.css



来源:https://stackoverflow.com/questions/9709715/using-two-conditional-css-if-statements-uses-neither-style-sheet

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