CSS编译器和转换IE黑客到条件css [英] CSS compilers and converting IE hacks to conditional css

查看:83
本文介绍了CSS编译器和转换IE黑客到条件css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跳到下面的问题,但首先,一个小的上下文。

Skip to bottom for question, but first, a little context.

所以我一直在研究CSS编译器(如Sass& Less)并且对他们真的很感兴趣,而不是因为他们帮助我更容易理解任何事情(我已经做了几年的css),而是他们削减了cruft,帮助我看到更容易。

So I have been looking into CSS compilers (like Sass & Less) for a while, and have been really interested in them, not because they help me understand anything easier (I've been doing css for a couple of years now) but rather they cut down on cruft and help me see things easier.

我最近一直在寻找可靠的实现inline-block(和clearfix),这需要大量的外部代码&黑客。现在根据所有的领域当局,我不应该把IE入侵在同一个网页我做我的CSS,我应该让他们有条件。但对我来说,这是一个真正的麻烦,通过和管理所有这些额外的代码,这就是为什么我真的很喜欢的东西。

I recently have been looking into reliably implementing inline-block (and clearfix), which require lots of extraneous code & hacks. Now according to all the authorities in the field, I shouldn't put IE hacks in the same page I do my CSS in, I should make them conditional. But for me that is a really big hassle to go through and manage all this additional code, which is why I really like things like Less. Instead of applying unsemantic classes, you specify a mixin and apply it once, and you're all set.

因此,我想我有一个轨道(我想要的),而不是应用非特殊的类,你指定一个mixin并应用一次,解释我的观点),但从根本上说,我在这些CSS编译器对我非常有用的点,并允许我抽象了很多的cruft,并可靠地应用它们一次,然后只是编译它。我想有一个方法能够编译IE特定的样式到自己的条件文件(ala Less / Sass),所以我不必处理管理2文件没有理由。

So I guess I got a little of the track (I wanted to explain my points) but bascially, I'm at the point where these CSS compilers are very useful for me, and allow me to abstract a lot of the cruft away, and reliably apply them once and then just compile it. I would like to have a way to be able to compile IE specific styles into their own conditional files (ala Less / Sass) so I don't have to deal with managing 2 files for no reason.

像脚本/应用程序一样运行,可以使下划线/明星黑客分开自己的文件存在吗?

Does anything like a script/applcation that runs and can make underscore / star hacks apart of their own file exist?

推荐答案

这不是一个编译器的技巧,但如果你想使用条件注释,而不必编译单独的浏览器样式表,你可以简单地使用HTML条件注释来注入一个样式钩。例如:

It's not really a compiler trick, but if you want to use conditional comments without having to compile separate per-browser stylesheets, you can simply use HTML conditional comments to inject a styling hook. For example:

    ...
</head>
<!--[if lte IE 6]><body class="ie6 ie7"><![endif]-->
<!--[if lte IE 7]><body class="ie7"><![endif]-->
<!--[if gte IE 8]><!--><body><!--<![endif]-->

现在,您可以将要应用于IE< = 6和IE< = 7的规则相同的样式表作为其余的规则:

Now you can target rules you want to apply to IE<=6 and IE<=7 in the same stylesheet as the rest of the rules:

body.ie6 #thing { position: relative; }
body.ie7 #otherthing { z-index: 0; }

这是IMO比 * html hack,这是最后可接受的CSS黑客。 (star hack和underscore hack是无效的CSS:avoid。)

This is IMO marginally cleaner than the * html hack, which is the last acceptable CSS hack. (The "star hack" and "underscore hack" are invalid CSS: avoid.)

这篇关于CSS编译器和转换IE黑客到条件css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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