有任何方法来做“如果IE”里面的CSS文件? [英] Is there any way to do "if IE" inside of a CSS file?

查看:142
本文介绍了有任何方法来做“如果IE”里面的CSS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你可以把条件语句加载不同的CSS文件,如果你在Internet Explorer,但你可以在一个CSS文件里面这样做?



我有一种情况,如果是Internet Explorer,我想要的边距是20,如果是任何其他浏览器,则为10。


 <! -  [If IE 8]> 
< div id =IE8>
<![endif] - >



<! - [If IE 8]>
< / div>
<![endif] - >然后,你的CSS可以这样做:


 #IE8 div.whatever {...} 


I know you can put conditional statements to load different CSS files if you are in Internet Explorer, but can you do this inside of a CSS file?

I have a situation where I want the right margin to be 20 if it's Internet Explorer but 10 if it's any other browser.

解决方案

The easiest way to handle this is with conditions in your HTML that put a div with a specific id around the rest of the page.

<!--[If IE 8]>
<div id="IE8">
<![endif]-->
  .
  .
  .
<!--[If IE 8]>
</div>
<![endif]-->

Then, your CSS can do this:

#IE8 div.whatever { ... }

This sort of makes all those CSS hacks unnecessary.

这篇关于有任何方法来做“如果IE”里面的CSS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆