css27】背景半透明rgba LESS實踐

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   tar   

今天有看到司徒正美《背景半透明rgba最佳實務》的文章和裡面推薦的一個線上工具 CSS背景顏色屬性值轉換  。

於是聯絡到自己的less庫,新技能Get。

內容如下:

 

 1 /*在你的less庫中加入以下代碼*/ 2 //rgba建立相容IE的rgba 3 #rgba(@r,@g,@b,@a){ 4     @c: rgba(@r,@g,@b,@a);  5     @c2 :argb(@c); 6     /* for IE9 IE8 IE7 not sure about IE6*/ 7     filter:~"progid:DXImageTransform.Microsoft.gradient(enabled=‘true‘,startColorstr=‘@{c2}‘, endColorstr=‘@{c2}‘)"; 8     background-color:@c; 9     :root &{10         /* 11          * IE9 由於rgba和filter都支援,會導致兩個顏色疊加,使用hack去除 12          * \9 代表 IE9 以下瀏覽器支援13          * :root 只有 IE9+ 以及其他現代瀏覽器支援14          * IE10 以上不再支援 filter15         */16         filter:none;17     }18 }

 使用方法:

/*LESS 裡面這樣寫*/.demo{ #rgba(255,0,0,0.3); }/*解析後的css為*/.demo {  filter: progid:DXImageTransform.Microsoft.gradient(enabled=‘true‘,startColorstr=‘#4dff0000‘, endColorstr=‘#4dff0000‘);  background-color: rgba(255, 0, 0, 0.3);}:root .demo { filter: none;}

 

本文為原創文章,會經常更新知識點以及修正一些錯誤,轉載請保留原出處。本文地址:http://www.cnblogs.com/css27/p/3785642.html 如果您覺得這文章對您有協助,可以打賞點錢給我,鼓勵我繼續寫一些高品質的博文。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.