CSS conditional comments for other Browsers except IE?

走远了吗. 提交于 2019-12-10 15:38:25

问题


So far I know, the conditional comments are only supported for different Versions of IE.

Likeways, can we provide conditional comments for other browsers too.

If Yes, How? If no, what could be the best alternative?


回答1:


Check out the CSS Browser Selector plugin. I use it on my site, you basically just write the CSS and tell which browser you want it to target. I use it on my site and it works great!

Hope it helps.




回答2:


CSS Conditional Comments are meant only for IE.. However, you can detect Firefox:

If the following code fails to exclusively detect Firefox..

<!--[if !IE]>
  ...statements...
<![endif]-->

Use "Downlevel-revealed Conditional Comments" to get it working...

<![if !IE]>
  ...statements...
<![endif]>

Example to force Firefox to use an exclusive css..

<![if !IE]>

  <link href="css/ff.css" rel="stylesheet" type="text/css" />

<![endif]>

Having said that, you should not be much worried about other browsers which are standard-compliant.




回答3:


As far as I know, CSS conditional statements are an IE exclusive. They should not be needed for other browser since they follow standards reasonably well. Why would you need them?




回答4:


There are not conditional comments for other browsers only IE and versions of IE.

You can using Javascript do checks for other browsers and apply styles as follows.

You can do a check for the browser to not be IE with conditional comments but just no.

I would suggest visiting W3.org and building your site to be functional with a standard conforming browser then use the conditional comments to fix up how it loads in IE if there are issues (there usually is).




回答5:


As noted in other answers there are no conditional comments for browsers other than IE. Using JS detection is the way to go here.

If you want to have the commented element affect the IE condition AND other browsers then simply do this:

<!--[if gt IE 8]><!-->
<link href="sample.css" rel="stylesheet" type="text/css" />
<!--><![endif]-->

As you can see from the syntax highlighting the link element is not commented out so it will be visible for non-IE browsers and for IE it will follow the condition (greater than IE 8 in this example).




回答6:


I wish there was a solution to this, especially for email rendering engines. There are even conditional comments for outlook, but none for Gmail.

<!--[if gte mso 9]>

<![endif]-->


来源:https://stackoverflow.com/questions/3043402/css-conditional-comments-for-other-browsers-except-ie

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