是否有任何仅 IE8 的 css hack?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3043094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:13:21  来源:igfitidea点击:

is there any IE8 only css hack?

cssinternet-explorer-8conditional-comments

提问by Jitendra Vyas

For Internet Explorer 8 (IE8) I'd like to use the following CSS:

对于 Internet Explorer 8 (IE8),我想使用以下 CSS:

color : green;

I would like to apply a hack which only affects IE8, not to IE9, IE6 and 7.

我想应用一个只影响 IE8 的 hack,而不是 IE9、IE6 和 7。

回答by Palantir

Use conditional comments in HTML, like this:

在 HTML 中使用条件注释,如下所示:

<!--[if IE 8]>
<style>...</style>
<![endif]-->

See here: http://www.quirksmode.org/css/condcom.html

见这里:http: //www.quirksmode.org/css/condcom.html

You can test for IE versions reliably and also be sure other browsers won't be confused.

您可以可靠地测试 IE 版本,并确保不会混淆其他浏览器。

回答by Paul Sweatte

Use media queries to separate each browser:

使用媒体查询来分隔每个浏览器:

/* IE6/7 uses media, */
@media, { 
        .dude { color: green; } 
        .gal { color: red; }
} 

/* IE8 uses 
color: green
.element { 
   color:green ;
 }
;
*/ @media all
<!--[if IE 8]>
<style>...</style>
<![endif]-->
{ .dude { color: brown; } .gal { color: orange; } } /* IE9 uses */ @media all and (monochrome:0) { .dude { color: yellow; } .gal { color: blue; } } /* IE10 and IE11 both use -ms-high-contrast */ @media all and (-ms-high-contrast:none) { .foo { color: green } /* IE10 */ *::-ms-backdrop, .foo { color: red } /* IE11 */ }

References

参考

回答by BalusC

Use \0.

使用\0.

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

*Your content* 

<!--[if IE 8]> 
</div>
<![endif]--> 

I however dorecommend conditional comments since you'd like to exclude IE9 as well and it's yet unpredictable whether this hack will affect IE9 as well or not.

但是确实建议使用条件注释,因为您也想排除 IE9,但无法预测此 hack 是否也会影响 IE9。

Regardless, I've never had the need for an IE8 specific hack. What is it, the IE8 specific problem which you'd like to solve? Is it rendering in IE8 standards mode anyway? Its renderer is pretty good.

无论如何,我从来不需要特定于 IE8 的 hack。是什么,您想解决的 IE8 特定问题?它是否以 IE8 标准模式呈现?它的渲染器非常好。

回答by ?iga

If needed small changes in CSS use \9it targets IE8 and below (IE6, IE7, IE8)

如果需要对 CSS 进行小的更改,请使用\9它针对 IE8 及以下(IE6、IE7、IE8)

#IE8 div.something
{ 
    color: purple; 
}

Best way is to use conditional comments in HTML, like this:

最好的方法是在 HTML 中使用条件注释,如下所示:

/*property-level hacks:*/
/*Standards, Edge*/
prop:val;
/*lte ie 11*/
prop:val;
/*lte ie 8*/
prop:val ;
/*lte ie 7*/
*prop:val;
/*lte ie 6*/
_prop:val;

/*other direction...*/
/*gte ie 8, NOT Edge*/
prop:val
.classname{
    *color: green; /* This is for IE8 Native browser alone */
}
;

回答by John Fisher

Doing something like this should work for you.

做这样的事情应该对你有用。

<!--[if lt IE 10]><div class="column IE10-fix"><![endif]-->
<!--[if !lt IE 10]><!--><div class="column"><!--<![endif]-->

Then your CSS can look like this:

那么你的 CSS 可以是这样的:

##代码##

回答by abluejelly

So a recent question prompted me to notice a selector set hack for excluding IE 8 only.

所以最近的一个问题促使我注意到一个选择器设置 hack排除 IE 8 。

.selector, #excludeIE8::before {}will cause IE 8 to throw out the entire selector set, while 5-7 and 9-11 will read it just fine. Any of the ::selectors (::first-line, ::before, ::first-letter, ::selection) will work, I've merely chosen ::beforeso the line reads accurately. Note that the goal of the fake ::beforeselector is to befake, so be sure to change it to something else if you actually have an element with the ID excludeIE8

.selector, #excludeIE8::before {}将导致 IE 8 丢弃整个选择器集,而 5-7 和 9-11 将读取它就好了。任何::选择器 ( ::first-line, ::before, ::first-letter, ::selection) 都可以使用,我只是选择了::before这样一行才能准确读取。请注意,fake::before选择器的目标伪造,因此如果您确实有一个带有 ID 的元素,请务必将其更改为其他内容excludeIE8

Interestingly enough, in modernbrowsers (FF 45-52, GC 49-57, Edge 25/13) a bad ::selector eats the entire selector set (dabblet demo). It seemsthat the last Windows version of Safari (and LTE IE 7, lol) doesn't have this behavior while still understanding ::before. Additionally, I can't find anything in the specto indicate that this is intended behavior, and since it would cause breakage on any selector setcontaining: ::future-legitimate-pseudoelement... I'm inclined to say this is a bug- and one that'll nibble our rears in the future.

有趣的是,在现代浏览器(FF 45-52、GC 49-57、Edge 25/13)中,一个糟糕的::选择器会吃掉整个选择器集(dabblet demo)。这似乎是Safari浏览器的最后一个Windows版本(和LTE IE 7,笑)没有这种行为,同时还了解::before。此外,我在规范中找不到任何表明这是预期行为的内容,并且因为它会导致任何包含以下内容的选择器损坏:::future-legitimate-pseudoelement......我倾向于说这是一个错误 - 并且会将来蚕食我们的臀部。



However, if you only want something at the property level (rather than the rule level), Ziga above had the best solution via appending ?\9(the space is key; do NOT copypaste that inlineas it uses an nbsp):

但是,如果您只想要属性级别(而不是规则级别)的某些内容,上面的 Ziga 通过附加提供了最佳解决方案?\9(空格是关键;不要复制粘贴该内联内容,因为它使用了 nbsp):

##代码##

Side note, I feel like a dirty necromancer- but I wanted somewhere to document the exclude-IE8-only selector set hack I found today, and this seemed to be the most fitting place.

旁注,我感觉自己像个肮脏的死灵法师——但我想在某个地方记录我今天发现的仅排除 IE8 的选择器集黑客,这似乎是最合适的地方。

回答by Vel Murugan S

For IE8 native browser alone:

仅针对 IE8 原生浏览器:

##代码##

回答by Damien_The_Unbeliever

Can you not use the hack you've already shown, and then use an IE7 and below hack to override it?

你能不使用你已经展示过的 hack,然后使用 IE7 及以下的 hack 来覆盖它吗?

回答by thepeer

There are various ways to get a class onto the HTML element, identifying which IE version you're contending with: Modernizr, the HTML 5 Boilerplate, etc - or just roll your own. Then you can use that class (eg .lt-ie9) in a normal CSS selector, no hack needed. If you only want to affect IE8 and not previous versions, put the old value back using a .lt-ie8 selector.

有多种方法可以将类添加到 HTML 元素上,以确定您正在使用的 IE 版本:ModernizrHTML 5 Boilerplate等 - 或者只是推出您自己的。然后你可以在普通的 CSS 选择器中使用那个类(例如 .lt-ie9),不需要 hack。如果您只想影响 IE8 而不是以前的版本,请使用 .lt-ie8 选择器将旧值放回原处。

回答by Sunkhern

I was looking for a good option for IE10 and below CSS styling (but it would work for IE8 only as well) and I came up with this idea:

我一直在为 IE10 及以下 CSS 样式寻找一个不错的选择(但它也只适用于 IE8),我想出了这个想法:

##代码##

I declare my div or whatever you want with an extra class, this allows me to have extra CSS in the same stylesheet in a very readable manner.

我用一个额外的类声明了我的 div 或任何你想要的东西,这允许我以一种非常易读的方式在同一个样式表中拥有额外的 CSS。

It's W3C valid and not a weird CSS hack.

它是 W3C 有效的,而不是奇怪的 CSS hack。