zoukankan      html  css  js  c++  java
  • css兼容处理-hack

    1.  浏览器兼容之旅的第二站:各浏览器的Hack写法
    2.  Browser CSS Hacks
    3.  Moving IE specific CSS into @media blocks
    4.  Detecting browsers javascript hacks
    5.  Browser Specific Hacks
    6.  Browser-Specific CSS Hacks
    7.  CSS hacks

    大家平时看得多的应该是IE浏览器的hack写法比较多,但对于现代浏览器,比如说Safari、Chrome、Firefox等浏览器的hack写法并不多见,甚至有的不知道怎么写。如果您是属于后者,根本不知道各浏览器下具有哪些hack手段,不要着急。因为Hugo GiraudelTim Pietrusky将各浏览器下的hack写整理放在了Browserhacks.com之上。

    一、Chrome浏览器

    选择器Hack

    /* Chrome 24- and Safari 5- */
    ::made-up-pseudo-element, .selector {
      代码放在这里
    }	
    

    媒体查询Hacks

    /* Chrome, Safari 3+ */
    @media screen and (-webkit-min-device-pixel-ratio:0) {
      代码放在这里	
    }	
    

    JavaScript Hack

    /* Chrome */
    var isChrome = Boolean(window.chrome);	
    

    二、Firefox浏览器

    属性选择器Hack

    /* Firefox 1.5 */
    body:empty .selector {
     样式代码放这里
    }
    /* Firefox 2+ */
    .selector, x:-moz-any-link {
     样式代码放这里	
    }
    /* Firefox 3+ */
    .selector, x:-moz-any-link; x:default {
     样式代码放这里	
    }
    /* Firefox 3.5+ */
    body:not(:-moz-handler-blocked) .selector {
     样式代码放这里	
    }	
    

    媒体查询Hack

    /* Firefox 3.5+, IE 9/10, Opera */
    @media screen and (min-resolution: +72dpi) {
     样式代码放这里		
    }
    /* Firefox 3.6+ */
    @media screen and (-moz-images-in-menus:0) {
     样式代码放这里		
    }
    /* Firefox 4+ */
    @media screen and (min--moz-device-pixel-ratio:0) {
     样式代码放这里		
    }	
    

    JavaScript Hack

    /* Firefox */
    var isFF = !!navigator.userAgent.match(/firefox/i);
    
    /* Firefox 2 - 13 */
    var isFF = Boolean(window.globalStorage);
    
    /* Firefox 2/3 */
    var isFF = /a/[-1]=='a';
    
    /* Firefox 3 */
    var isFF = (function x(){})[-5]=='x';	
    

    混合型Hack

    /* Firefox 3+ */
    @-moz-document url-prefix() {
     样式代码放这里		
    }	
    

    三、Opera浏览器

    属性选择器Hack

    /* Opera 9.25, Safari 2/3.1 */
    *|html[xmlns*=""] .selector {
     样式代码放这里	
    }
    
    /* Opera 9.27 and below, Safari 2 */
    html:first-child .selector {
     样式代码放这里	
    }
    
    /* Opera 9.5+ */
    noindex:-o-prefocus, .selector {
     样式代码放这里	
    }	
    

    媒体查询Hack

    /* Opera 7 */
    @media all and (min- 0px){
     样式代码放这里		
    }
    
    /* Opera 12- */
    @media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) {
     样式代码放这里		
    }
    
    /* Opera, Firefox 3.5+, IE 9/10 */
    @media screen and (min-resolution: +72dpi) {
     样式代码放这里		
    }
    
    /* Opera, IE 8/9/10 */
    @media screen {
     样式代码放这里		
    }	
    

    JavaScript Hack

    /* Opera 9.64- */
    var isOpera = /^function (/.test([].sort);
    
    /* Opera 12- */
    var isOpera = Boolean(window.opera);	
    

    四、Safari浏览器

    属性选择器Hack

    /* Safari 2/3 */
    html[xmlns*=""] body:last-child .selector {
     样式代码放这里		
    } 
    html[xmlns*=""]:root .selector  {
     样式代码放这里		
    }
    
    /* Safari 2/3.1, Opera 9.25 */
    *|html[xmlns*=""] .selector {
     样式代码放这里		
    }
    
    /* Safari 5- and Chrome 24- */
    ::made-up-pseudo-element, .selector {
     样式代码放这里		
    }	
    

    媒体查询Hack

    /* Safari */
    var isSafari = /a/.__proto__=='//';	
    

    五、IE浏览器

    选择器Hack

    /* IE 6 and below */
    * html .selector  {
     样式代码放这里		
    } 
    .suckyie6.selector {
     样式代码放这里		
    } /* .suckyie6 can be any unused class */
    
    /* IE 7 and below */
    .selector, {
     样式代码放这里		
    }
    
    /* IE 7 */
    *:first-child+html .selector {
      样式代码放这里	
    } 
    .selector, x:-IE7 {
     样式代码放这里		
    } 
    *+html .selector {
     样式代码放这里		
    } 
    
    /* Everything but IE 6 */
    html > body .selector {
     样式代码放这里		
    }
    
    /* Everything but IE 6/7 */
    html > /**/ body .selector {
      样式代码放这里	
    }
    head ~ /* */ body .selector {
     样式代码放这里		
    }
    
    /* Everything but IE 6/7/8 */
    :root *> .selector {
     样式代码放这里		
    } 
    body:last-child .selector {
     样式代码放这里		
    } 
    body:nth-of-type(1) .selector {
     样式代码放这里		
    } 
    body:first-of-type .selector {
     样式代码放这里		
    }	
    

    属性/属性值 Hack

    /* IE 6 */
    .selector { _color: blue; } 
    .selector { -color: blue; }
    
    /* IE 6/7 - any combination of these characters: 
     ! $ & * ( ) = % + @ , . / ` [ ] # ~ ? : <  > | */
    .selector { !color: blue; } 
    .selector { $color: blue; } 
    .selector { &color: blue; } 
    .selector { *color: blue; } 
    /* ... */
    
    /* IE 6/7 - acts as an !important */
    .selector { color: blue !ie; } 
    /* string after ! can be anything */
    
    /* IE 8/9 */
    .selector { color: blue0/; } 
    /* must go at the END of all rules */
    
    /* IE 9/10 */
    .selector:nth-of-type(1n) { color: blue9; }
    
    /* IE 6/7/8/9/10 */
    .selector { color: blue9; } 
    .selector { color/***/: blue9; }
    
     /* Everything but IE 6 */
    .selector { color/**/: blue; }
    

    媒体查询Hack

    /* IE 6/7 */
    @media screen9 {
     样式代码放这里		
    }
    
    /* IE 6/7/8 */
    @media 0screen\,screen9 {
     样式代码放这里		
    }
    
    /* IE 8 */
    @media 0screen {
     样式代码放这里		
    }
    
    /* IE 8/9/10 & Opera */
    @media screen0 {
     样式代码放这里		
    }
    
    /* IE 9/10, Firefox 3.5+, Opera */
    @media screen and (min-resolution: +72dpi) {
     样式代码放这里		
    }
    
    /* IE 9/10 */
    @media screen and (min-00) {
     样式代码放这里		
    }
    
    /* IE 10+ */
    @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
     样式代码放这里		
    }
    
    /* Everything but IE 6/7/8 */
    @media screen and (min- 400px) {
     样式代码放这里		
    }
    

    JavaScript Hack

    /* IE <= 8 */
    var isIE = 'v'=='v';	
    
    /* IE 6 */
    (checkIE = document.createElement("b")).innerHTML = "<!--[if IE 6]><i></i><![endif]-->"; 
    var isIE = checkIE.getElementsByTagName("i").length == 1;	
    
    /* IE 7 */
    (checkIE = document.createElement("b")).innerHTML = "<!--[if IE 7]><i></i><![endif]-->"; 
    var isIE = checkIE.getElementsByTagName("i").length == 1;
    navigator.appVersion.indexOf("MSIE 7.")!=-1	
    
    /* IE 8 */
    (checkIE = document.createElement("b")).innerHTML = "<!--[if IE 8]><i></i><![endif]-->"; 
    var isIE = checkIE.getElementsByTagName("i").length == 1;	
    
    /* IE 9 */
    (checkIE = document.createElement("b")).innerHTML = "<!--[if IE 9]><i></i><![endif]-->"; 
    var isIE = checkIE.getElementsByTagName("i").length == 1;	
    
    /* IE 10 */
    var isIE = eval("/*@cc_on!@*/false") && document.documentMode === 10;	
    
    /* IE 10 */
    var isIE = document.body.style.msTouchAction != undefined;
    

    上面列出各个浏览器下hack的写法,当然在实际运用之中并不建议使用hack。如果你的页面需要hack来处理时,请先检查你的css或者js,如果实在无法达到要求,在考虑使用hack来处理。

    转载自http://www.w3cplus.com/

  • 相关阅读:
    Json 格式化, 排序, 标准格式 ,修改字段名 @JSONField @JsonIgnore @JsonIgnoreProperties
    skywalking 服务间链路追踪 (4) --- 项目中追踪各个方法, 监测方法运行时间
    skywalking 服务间链路追踪 (3) ---整合docker使用
    skywalking 服务间链路追踪 (2) ---使用
    skywalking 服务间链路追踪 (1) ---安装
    Exception AOP 异常处理
    messageHelper 统一管理项目的中message
    Json 对象比较
    Nginx 针对建立TCP连接优化
    Nginx 建立三次握手
  • 原文地址:https://www.cnblogs.com/yuxingyoucan/p/6044731.html
Copyright © 2011-2022 走看看