仅针对 ie8 和 ie9(不适用于 ie7)

发布于 2024-10-22 23:17:20 字数 549 浏览 7 评论 0原文

我有一个简单的页面,一切工作正常,除了 ie8 和 ie9 将我的一个元素向右移动 1px,其重要原因是它会在黑色背景上产生一条 1px 的白线。可怕。 我已经尝试了很多 css hacks,以及 ie 条件注释,但是像

到目前为止我的代码

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

编辑:已解决,这似乎是 IETester 中的一个错误,在正确安装的资源管理器中一切正常。

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. 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. Only <!--[if gte IE 7]> is recognised, targets ie7 as well - but ie7 renders the page pixel perfect. 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. Ie8 and 9 seem to think they are 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

唠甜嗑 2024-10-29 23:17:20

如果这只是您需要修改的一件事,您还可以使用:

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

这将为 html 元素提供 .ie7 或 .ie8 类,具体取决于它们正在使用的内容或您指定的内容。然后,您可以定位要覆盖的任何内容,例如:

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

.ie8 #promo {margin-left:-3px;}< /code> 并单独定位它们。您还可以为 IE 9 指定规则。

并将其包含在主样式表中靠近底部的位置。这使您不必制作大量不同的样式表。

至于 IE9 不渲染为 IE9,我认为如果由于我完全不知道的原因安装了 Internet Explorer,Internet Explorer 实际上会回退到以前的渲染器。我认为 Paul Irish 在他关于 HTML5 Boilerplate 的演讲中提到了这一点onTwik 网站上。

他们在 .htaccess 文件中使用一些代码来强制 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>

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. You can then target whatever you want to override, like:

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

.ie8 #promo {margin-left:-3px;} and target them individually. You could also specify a rule for 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. I think Paul Irish mentions it on his talk on the HTML5 Boilerplate on the onTwik website.

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:

<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    BrowserMatch MSIE ie
    Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
  </IfModule>
</IfModule>
难以启齿的温柔 2024-10-29 23:17:20

我建议使用带有 IE 条件注释的实际样式表。

本文提供了很好的概述,但我会避免讨论黑客部分。

http://css-tricks.com/how-to-创建仅 ie 样式表/

I would recommend using an actual stylesheet with the IE conditional comments.

This article gives a good overview, but I'd avoid the hacks section.

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

中性美 2024-10-29 23:17:20

您是否正在执行任何强制 IE8/9 进入兼容性视图的操作?如果是这样,您可能会无意中告诉这些浏览器将自己视为 IE7,至少就解释这些条件而言是这样。

Are you doing anything that forces IE8/9 to go into Compatibility View? 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文