大家一起學習less 6:一些有用的混合函數

來源:互聯網
上載者:User
文章目錄
  • 水平漸層
  • 水平漸層2
  • 邊框顏色
  • 下拉陰影(drop-shadow)
  • 圓角
  • 圓角
  • 透明度
  • 緩動時間長度
水平漸層

預設是淺色。

.gradient(@color: #F5F5F5, @start: #EEE, @stop: #FFF) {  background: @color;  background: -webkit-gradient(linear,                               left bottom,                               left top,                               color-stop(0, @start),                               color-stop(1, @stop));  background: -ms-linear-gradient(bottom,                                  @start,                                  @stop);  background: -moz-linear-gradient(center bottom,                                   @start 0%,                                   @stop 100%);}

使用樣本

.wh{     width:500px;     height:50px}.wh{   .gradient //混合到.wh類裡面}/*最後產生*/.wh {background: #f5f5f5;background: -webkit-gradient(linear, left bottom, left top, color-stop(0, #eeeeee), color-stop(1, #ffffff));background: -ms-linear-gradient(bottom, #eeeeee, #ffffff);background: -moz-linear-gradient(center bottom, #eeeeee 0%, #ffffff 100%);} 
水平漸層2

預設是深色,並且後兩個參數要求是0~256的數值

.bw-gradient(@color: #F5F5F5, @start: 0, @stop: 255) {  background: @color;  background: -webkit-gradient(linear,                               left bottom,                               left top,                               color-stop(0, rgb(@start,@start,@start)),                               color-stop(1, rgb(@stop,@stop,@stop)));  background: -ms-linear-gradient(bottom,                                  rgb(@start,@start,@start) 0%,                                  rgb(@start,@start,@start) 100%);  background: -moz-linear-gradient(center bottom,                                   rgb(@start,@start,@start) 0%,                                   rgb(@stop,@stop,@stop) 100%);}

使用樣本

.wh{  .bw-gradient(#ff0000, 55, 144)}
邊框顏色
.bordered(@top-color: #EEE, @right-color: #EEE, @bottom-color: #EEE, @left-color: #EEE) {  border-top: solid 1px @top-color;  border-left: solid 1px @left-color;  border-right: solid 1px @right-color;  border-bottom: solid 1px @bottom-color;}
下拉陰影(drop-shadow)
.drop-shadow(@x-axis: 0, @y-axis: 1px, @blur: 2px, @alpha: 0.1) {  -webkit-box-shadow: @x-axis @y-axis @blur rgba(0, 0, 0, @alpha);  -moz-box-shadow: @x-axis @y-axis @blur rgba(0, 0, 0, @alpha);  box-shadow: @x-axis @y-axis @blur rgba(0, 0, 0, @alpha);}
圓角

只有一個參數

.rounded(@radius: 2px) {  -webkit-border-radius: @radius;  -moz-border-radius: @radius;  border-radius: @radius;  -moz-background-clip: padding; -webkit-background-clip: padding-box; background-clip: padding-box; }
圓角

有四個參數

.border-radius(@topright: 0, @bottomright: 0, @bottomleft: 0, @topleft: 0) {  -webkit-border-top-right-radius: @topright;  -webkit-border-bottom-right-radius: @bottomright;  -webkit-border-bottom-left-radius: @bottomleft;  -webkit-border-top-left-radius: @topleft;  -moz-border-radius-topright: @topright;  -moz-border-radius-bottomright: @bottomright;  -moz-border-radius-bottomleft: @bottomleft;  -moz-border-radius-topleft: @topleft;  border-top-right-radius: @topright;  border-bottom-right-radius: @bottomright;  border-bottom-left-radius: @bottomleft;  border-top-left-radius: @topleft;  -moz-background-clip: padding; -webkit-background-clip: padding-box; background-clip: padding-box; }
透明度

對IE支援不好

.opacity(@opacity: 0.5) {  -moz-opacity: @opacity;  -khtml-opacity: @opacity;  -webkit-opacity: @opacity;  opacity: @opacity;}
緩動時間長度
.transition-duration(@duration: 0.2s) {  -moz-transition-duration: @duration;  -webkit-transition-duration: @duration;  transition-duration: @duration;}
.columns(@colwidth: 250px, @colcount: 0, @colgap: 50px, @columnRuleColor: #EEE, @columnRuleStyle: solid, @columnRuleWidth: 1px) {  -moz-column-width: @colwidth;  -moz-column-count: @colcount;  -moz-column-gap: @colgap;  -moz-column-rule-color: @columnRuleColor;  -moz-column-rule-style: @columnRuleStyle;  -moz-column-rule-width: @columnRuleWidth;  -webkit-column-width: @colwidth;  -webkit-column-count: @colcount;  -webkit-column-gap: @colgap;  -webkit-column-rule-color: @columnRuleColor;  -webkit-column-rule-style: @columnRuleStyle;  -webkit-column-rule-width: @columnRuleWidth;  column-width: @colwidth;  column-count: @colcount;  column-gap: @colgap;  column-rule-color: @columnRuleColor;  column-rule-style: @columnRuleStyle;  column-rule-width: @columnRuleWidth;}

https://github.com/dmitryf/elements/blob/master/elements.less

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.