CSS属性兼容写法

  1. 一种是用js判断兼容性

    // JS
    if ("CSS" in window && "supports" in window.CSS) {
    	var support = window.CSS.supports("mix-blend-mode","difference");
    	support = support?"mix-blend-mode":"no-mix-blend-mode";
    	document.documentElement.className += support;
    }
    
    // CSS
    h1 { color: #000; }
    .mix-blend-mode body {
    	background-image: linear-gradient(90deg,#fff 49.9%,#000 50%);
    }
    
    .mix-blend-mode h1 {
       color: #fff;
       mix-blend-mode: difference;
    }
    
  2. 用CSS中的@supports

    @supports (mix-blend-mode: difference) {
        body {
            background-image: linear-gradient(90deg,#fff 49.9%,#000 50%)
        }
        h1 {
            color: #fff;
            mix-blend-mode: difference;
        }
    }
    
posted @ 2019-01-14 16:05  kitebear  阅读(732)  评论(0编辑  收藏  举报