如何为IE9单独定义特定的CSS规则?

前端之家收集整理的这篇文章主要介绍了如何为IE9单独定义特定的CSS规则?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
朋友请帮我定义IE9的具体css规则?
例如像这样
  1. /* IE 6 fix */
  2. * html .twit-post .delete_note a { background-position-y: 2px; }
  3. * html .twit-post .delete_note a:hover { background-position-y: -14px; }

解决方法

注意接受的答案也是针对IE10。因此,为了更完整的列表:

IE 6

  1. * html .ie6 {property:value;}

要么

  1. .ie6 { _property:value;}

IE 7

  1. *+html .ie7 {property:value;}

要么

  1. *:first-child+html .ie7 {property:value;}

IE 6和7

  1. @media screen\9 {
  2. .ie67 {property:value;}
  3. }

要么

  1. .ie67 { *property:value;}

要么

  1. .ie67 { #property:value;}

IE 6,7和8

  1. @media \0screen\,screen\9 {
  2. .ie678 {property:value;}
  3. }

IE 8

  1. html>/**/body .ie8 {property:value;}

要么

  1. @media \0screen {
  2. .ie8 {property:value;}
  3. }

IE 8标准模式

  1. .ie8 { property /*\**/: value\9 }

IE 8,9和10

  1. @media screen\0 {
  2. .ie8910 {property:value;}
  3. }

仅IE 9

  1. @media screen and (min-width:0) and (min-resolution: .001dpcm) {
  2. // IE9 CSS
  3. .ie9{property:value;}
  4. }

IE 9及以上

  1. @media screen and (min-width:0) and (min-resolution: +72dpi) {
  2. // IE9+ CSS
  3. .ie9up{property:value;}
  4. }

IE 9和10

  1. @media screen and (min-width:0) {
  2. .ie910{property:value;}
  3. }

仅IE 10

  1. _:-ms-lang(x),.ie10 { property:value\9; }

IE 10及以上

  1. _:-ms-lang(x),.ie10up { property:value; }

要么

  1. @media all and (-ms-high-contrast: none),(-ms-high-contrast: active) {
  2. .ie10up{property:value;}
  3. }

IE 11(及以上..)

  1. _:-ms-fullscreen,:root .ie11up { property:value; }

Javascript替代品

Modernizr

Modernizr runs quickly on page load to detect features; it then
creates a JavaScript object with the results,and adds classes to the
html element

User agent selection

Javascript:

  1. var b = document.documentElement;
  2. b.setAttribute('data-useragent',navigator.userAgent);
  3. b.setAttribute('data-platform',navigator.platform );
  4. b.className += ((!!('ontouchstart' in window) || !!('onmsgesturechange' in window))?' touch':'');

添加(例如)以下到html元素:

  1. 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)'
  2. data-platform='Win32'

允许非常有针对性的CSS选择器,例如:

  1. html[data-useragent*='Chrome/13.0'] .nav{
  2. background:url(img/radial_grad.png) center bottom no-repeat;
  3. }

脚注

如有可能,请避免浏览器定位。识别并修复您识别的任何问题。支持progressive enhancementgraceful degradation.考虑到这一点,这是一个“理想的世界”场景,在生产环境中并不总是可以实现的,因此上述方法应该有助于提供一些好的选择。

归因/基本阅读

> Keith Clarke
> Paul Irish
> Web Devout
> The Spanner

猜你在找的CSS相关文章