IE8 CSS Hack - 最好的方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5635829/
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
IE8 CSS Hack - best method?
提问by Dancer
Can anyone recommend the best way to hack IE8 styling via CSS, I've recently been making IE8 render as IE7 for ease - but wondered if it was best to add IE8 hacks?
任何人都可以推荐通过 CSS 破解 IE8 样式的最佳方法,我最近一直在让 IE8 呈现为 IE7 以轻松 - 但想知道是否最好添加 IE8 hacks?
回答by kapa
You should reverse your method. First your site should look good in modern browsers (like Firefox, Chrome, Opera, IE 9), and then you can start worrying about the others.
你应该颠倒你的方法。首先,您的网站在现代浏览器(如 Firefox、Chrome、Opera、IE 9)中应该看起来不错,然后您就可以开始担心其他浏览器了。
As others suggested, conditional comments can be your friend.
正如其他人所建议的那样,有条件的评论可以成为您的朋友。
First, you should develop your CSS to look fine in the modern browsers. Then check IE8, see what problems you get. If you need to, include an IE-specific stylesheet. After that, you can check in IE7 and then IE6 if you support it, and add further fixes.
首先,您应该开发您的 CSS,使其在现代浏览器中看起来不错。然后检查IE8,看看你遇到了什么问题。如果需要,请包含特定于 IE 的样式表。之后,您可以检查 IE7,然后检查 IE6(如果您支持它),并添加进一步的修复。
An example:
一个例子:
<link rel="stylesheet" href="normal.css" type="text/css" />
<!--[if lt IE 9]><link rel="stylesheet" type="text/css" href="ie8.css"><![endif]-->
<!--[if lt IE 8]><link rel="stylesheet" type="text/css" href="ie7.css"><![endif]-->
In this case you include normal.css
which is for modern browsers. You found some strange IE8 issues, so in ie8.css
you fix the problems. You don't have to include all your selectors in this, only the ones that need a fix (the values will be overridden for IE 8 and lower). After that, if there are still some strange things in IE7, you can add your ie7.css
and fix those, and so on.
在这种情况下,您包括normal.css
适用于现代浏览器的内容。你发现了一些奇怪的 IE8 问题,所以在ie8.css
你修复这些问题。您不必在其中包含所有选择器,只需包含需要修复的选择器(IE 8 及更低版本的值将被覆盖)。之后,如果IE7中还有一些奇怪的东西,你可以添加ie7.css
并修复它们,等等。
Please refer to the links the others gave you to get more information on the usage of conditional comments.
请参阅其他人给您的链接以获取有关使用条件注释的更多信息。
Finally:making IE8 render as IE7 for ease
is never a good idea, and should be avoided. IE7 is the far past (in the IT world, IE8 should be the far past either...), develop for the present and the future, and after that you can care about the people who are still stuck with old technology (based on your audience and business plan).
最后:making IE8 render as IE7 for ease
永远不是一个好主意,应该避免。IE7 已经是遥远的过去了(在 IT 世界里,IE8 也应该是遥远的过去......),为现在和未来而开发,之后你可以关心那些仍然停留在旧技术上的人(基于您的受众和商业计划)。
回答by Daniel A. White
Use conditional comments.
使用条件注释。
回答by eddie yang
As other answers posted,you could use Conditional Comments,but that would add one HTTP request when user is using IE8. You can use the \0 hack in the css file
正如发布的其他答案一样,您可以使用条件注释,但是当用户使用 IE8 时,这会添加一个 HTTP 请求。您可以在 css 文件中使用 \0 hack
img{
width:200px;//other broswers
width:100px<!--[if lt IE 10]><div class="column IE10-fix"><![endif]-->
<!--[if !lt IE 10]><!--><div class="column"><!--<![endif]-->
;//only IE8
}
回答by RoToRa
Can you explain a bit more what you want?
你能解释一下你想要什么吗?
Generally, IE8 is quite standards compatible, so just make sure your HTML document is in standards mode and give IE8 the same stylesheet as any other browser.
通常,IE8 与标准非常兼容,因此只需确保您的 HTML 文档处于标准模式,并为 IE8 提供与任何其他浏览器相同的样式表。
If IE is acting up, then the best solution is to use Conditional Commentsto give IE a separate stylesheet.
如果 IE 出现问题,那么最好的解决方案是使用条件注释为 IE 提供一个单独的样式表。
回答by Sunkhern
I was looking for a good option for IE10 and below CSS styling (but it would work for IE8 only as well), I didn't wanted an extra stylesheet for readability 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。
回答by entropo
Use the ie7-jsJavascript library, which does some magic to make older IE versions behave more like proper browsers with their handling of HTML and CSS. Then, as others have suggested, write your code in a standards-compliant manner which behaves well with the latest versions of Chrome, Firefox, Opera, etc.
使用ie7-jsJavascript 库,它有一些神奇的作用,可以使旧的 IE 版本在处理 HTML 和 CSS 时表现得更像正确的浏览器。然后,正如其他人所建议的那样,以符合标准的方式编写代码,该方式与最新版本的 Chrome、Firefox、Opera 等表现良好。
回答by reyhappen
ie8 only: the best way is
仅 ie8:最好的方法是
body{background:#f00\0/;}
body{background:#f00\0/;}
\0/ is the Ie8 CSS Hack
\0/ 是 Ie8 CSS Hack