简体   繁体   English

仅定位ie8和ie9(不定位ie7)

[英]target ie8 and ie9 only (not ie7)

I have an simple page, and everything works fine except ie8 and ie9 moves one of my elements 1px to the right, and its significant b/c it results in a 1px white line straight on black background. 我有一个简单的页面,除了ie8和ie9将我的一个元素向右移动1px之外,其他所有东西都工作正常,它的有效b / c导致在黑色背景上直线出现1px白线。 Horrible. 可怕。 I've tried a lot of css hacks, and ie conditional comments but things like <!--[if gt IE 7]> or <!--[if gte IE 8]> aren't working. 我已经尝试了很多CSS hack,例如条件注释,但是<!--[if gt IE 7]><!--[if gte IE 8]>都无法正常工作。 Only <!--[if gte IE 7]> is recognised, targets ie7 as well - but ie7 renders the page pixel perfect. 仅识别<!--[if gte IE 7]>也将ie7作为目标-但ie7可使页面像素完美。 So I've tried to rollback the changes for ie7 with additional comment <!--[if IE 7]> but this killed the fixes in later ie's. 因此,我尝试通过附加注释<!--[if IE 7]>回退ie7的更改,但这会在以后的ie中终止修复。 Ie8 and 9 seem to think they are ie7. IE8和9似乎认为它们是IE7。

My code so far 到目前为止我的代码

<!--[if gte IE 7]>
<style>
#promo {margin-left:-1px;}
</style>
<![endif]-->

EDIT: Solved, It seems it is a bug in IETester, anything works fine in properly installed Explorers. 编辑:已解决,看来这是IETester中的错误,在正确安装的资源管理器中一切正常。

I would recommend using an actual stylesheet with the IE conditional comments. 我建议使用带有IE条件注释的实际样式表。

This article gives a good overview, but I'd avoid the hacks section. 本文提供了很好的概述,但是我会避免使用“ hacks”部分。

http://css-tricks.com/how-to-create-an-ie-only-stylesheet/ http://css-tricks.com/how-to-create-an-ie-only-stylesheet/

If it's just one thing you need to bump, you can also use: 如果您只是需要碰碰一件事,还可以使用:

<!--[if IE 7 ]>    <html class= "ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class= "ie8"> <![endif]-->

This will give the html element the class of .ie7 or .ie8 depending on what they're using or what you've specified. 这将使html元素具有.ie7或.ie8类,具体取决于它们使用的是什么或指定的内容。 You can then target whatever you want to override, like: 然后,您可以定位要覆盖的对象,例如:

.ie7 #promo {margin-left:-1px;} or .ie7 #promo {margin-left:-1px;}

.ie8 #promo {margin-left:-3px;} and target them individually. .ie8 #promo {margin-left:-3px;} ,然后分别定位它们。 You could also specify a rule for IE 9. 您也可以为IE 9指定规则。

And include it in your main stylesheet, near the bottom. 并将其包含在底部附近的主样式表中。 This saves you from having to make a lot of different stylesheets. 这使您不必制作许多不同的样式表。

As far as IE9 not rendering as IE9, I think Internet Explorer will actually fallback into a previous renderer if it's installed for reasons that are totally unknown to me. 至于IE9不能渲染为IE9的情况,我认为如果安装Internet Explorer是出于我完全不知道的原因,它实际上将回退到以前的渲染器。 I think Paul Irish mentions it on his talk on the HTML5 Boilerplate on the onTwik website. 我认为Paul Irish在onTwik网站上关于HTML5 Boilerplate的演讲中提到了这一点

They use some code in their .htaccess file to force IE to use the most recent rendering engine, and will actually force IE to use the Chrome engine if it's installed: 他们在.htaccess文件中使用一些代码来强制IE使用最新的呈现引擎,并且如果安装了IE,则实际上将强制IE使用Chrome引擎:

<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    BrowserMatch MSIE ie
    Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
  </IfModule>
</IfModule>

Are you doing anything that forces IE8/9 to go into Compatibility View? 您是否正在执行迫使IE8 / 9进入“兼容性视图”的措施? If so, you could be unwittingly telling those browsers to think of themselves as IE7, at least as far as it matters for interpreting those conditionals. 如果是这样,那么您可能会不经意间告诉那些浏览器将自己视为IE7,至少在解释那些条件时才是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM