CSS奇淫巧技

CSS很简单,也很复杂,人人都会用,但能用好用精就是一门艺术了。

CSS奇淫巧技

改变选中文本背景颜色

     *::selection {
        color: #fff;
        background: #000;
     }
    *::-moz-selection {    
        /*Only Firefox still needs a prefix*/
        color: #fff;
        background: #000;
     }

背景色渐变

线性渐变

  • 语法解释:

    • 第一次参数表示渐变的方向,可以用角度或者to top|bottom|left|right表示;
    • 第2-n个参数表示颜色,在颜色后面可以加上该颜色结束的位置,用百分比或者直接用长度表示

      background: linear-gradient(to bottom, red 20%, lightgreen 40%, blue);
      
  • 跨浏览器实施渐变,这里包含了所有前缀的渐变设置。

         background-color: #F07575; /* fallback color if gradients are not supported */
         background-image: -webkit-linear-gradient(top, hsl(0, 80%, 70%), #bada55); /* For Chrome 25 and Safari 6, iOS 6.1, Android 4.3 */
         background-image: -moz-linear-gradient(top, hsl(0, 80%, 70%), #bada55); /* For Firefox (3.6 to 15) */
         background-image: -o-linear-gradient(top, hsl(0, 80%, 70%), #bada55); /* For old Opera (11.1 to 12.0) */ 
         background-image: linear-gradient(to bottom, hsl(0, 80%, 70%), #bada55); /* Standard syntax; must be last */
         filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#0048607d', endColorstr='#a11c952d',GradientType=0 ); /* IE6-8 */