朋友,请帮我定义IE9的具体css规则?例如像这样
/* IE 6 fix */
* html .twit-post .delete_note a { background-position-y: 2px; }
* html .twit-post .delete_note a:hover { background-position-y: -14px; }
朋友,请帮我定义IE9的具体css规则?例如像这样
/* IE 6 fix */
* html .twit-post .delete_note a { background-position-y: 2px; }
* html .twit-post .delete_note a:hover { background-position-y: -14px; }
请注意,接受的答案也针对 IE10。因此,对于更完整的列表:
* html .ie6 {property:value;}
或者
.ie6 { _property:value;}
*+html .ie7 {property:value;}
或者
*:first-child+html .ie7 {property:value;}
@media screen\9 {
.ie67 {property:value;}
}
或者
.ie67 { *property:value;}
或者
.ie67 { #property:value;}
@media \0screen\,screen\9 {
.ie678 {property:value;}
}
html>/**/body .ie8 {property:value;}
或者
@media \0screen {
.ie8 {property:value;}
}
.ie8 { property /*\**/: value\9 }
@media screen\0 {
.ie8910 {property:value;}
}
@media screen and (min-width:0) and (min-resolution: .001dpcm) {
// IE9 CSS
.ie9{property:value;}
}
@media screen and (min-width:0) and (min-resolution: +72dpi) {
// IE9+ CSS
.ie9up{property:value;}
}
@media screen and (min-width:0) {
.ie910{property:value;}
}
_:-ms-lang(x), .ie10 { property:value\9; }
_:-ms-lang(x), .ie10up { property:value; }
或者
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
.ie10up{property:value;}
}
_:-ms-fullscreen, :root .ie11up { property:value; }
Modernizr 在页面加载时快速运行以检测功能;然后它创建一个带有结果的 JavaScript 对象,并将类添加到 html 元素
Javascript:
var b = document.documentElement;
b.setAttribute('data-useragent', navigator.userAgent);
b.setAttribute('data-platform', navigator.platform );
b.className += ((!!('ontouchstart' in window) || !!('onmsgesturechange' in window))?' touch':'');
在元素中添加(例如)以下html
内容:
data-useragent='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)'
data-platform='Win32'
允许非常有针对性的 CSS 选择器,例如:
html[data-useragent*='Chrome/13.0'] .nav{
background:url(img/radial_grad.png) center bottom no-repeat;
}
如果可能,请避免浏览器定位。识别并修复您发现的任何问题。支持渐进增强和优雅降级。考虑到这一点,这是一个“理想世界”的场景,并非总是可以在生产环境中获得,因此——上述内容应该有助于提供一些不错的选择。
您可以在 CSS 样式前面加上
:root
使其特定于 IE9,如下所示:
:root #element { color:pink \0/IE9; } /* IE9 */
使用IE 条件注释:
<!--[if ie 9]>
your stuff here
<![endif]-->
\9 是 Internet Explorer 特有的“CSS hack”。
这仅仅意味着 CSS 的一个特定行以 \9 结尾;
在您的示例中,如果您的 CSS 看起来像这样......
html .twit-post .delete_note a
{
background-position-y: 2px\9;
}
html .twit-post .delete_note a:hover
{
background-position-y: -14px\9;
}
结果将是 background-position-y: -14px; 在 IE 9 中
我认为你可以做同样的事情,就像你想为 IE6 编写特定代码但说 IE9 一样:)
<!--[if IE 9]>
Special instructions for IE 9 here
<![endif]-->
使用条件 CSS:(将代码<head>
放在 html 的上方,IE9 会读取那个额外的 CSS 文件)
<!--[if (gte IE 9)|!(IE)]><!-->
place the link to the CSS file here
<![endif]-->
这意味着该方法是使用新的 CSS 文件而不是类中的 hack,这保证了 CSS 是有效的。
我发现在某些情况下使用负值(使用编译器编译 LESS 文件时)使用:
margin-right: -15px\9; /* This fails */
margin-right: ~"-18px\9"; /* This passes */
您不需要针对 IE9。它能够处理现代 css,不应该被黑客入侵。这是一种过时的开发方法。