一、變量javascript
Sass css
$mainColor: #0982c1; $siteWidth: 1024px; $borderStyle: dotted; body { color: $mainColor; border: 1px $borderStyle $mainColor; max-width: $siteWidth; }
Lesshtml
@mainColor: #0982c1; @siteWidth: 1024px; @borderStyle: dotted; body { color: @mainColor; border: 1px @borderStyle @mainColor; max-width: @siteWidth; }
二、混入java
Sasssass
/* Sass mixin error with (optional) argument $borderWidth which defaults to 2px if not specified */ @mixin error($borderWidth: 2px) { border: $borderWidth solid #F00; color: #F00; } .generic-error { padding: 20px; margin: 4px; @ include error(); /* Applies styles from mixin error */ } .login-error { left: 12px; position: absolute; top: 20px; @ include error(5px); /* Applies styles from mixin error with argument $borderWidth equal to 5px*/ }
Lessless
/* LESS mixin error with (optional) argument @borderWidth which defaults to 2px if not specified */ .error(@borderWidth: 2px) { border: @borderWidth solid #F00; color: #F00; } .generic-error { padding: 20px; margin: 4px; .error(); /* Applies styles from mixin error */ } .login-error { left: 12px; position: absolute; top: 20px; .error(5px); /* Applies styles from mixin error with argument @borderWidth equal to 5px */ }
三、繼承 (當咱們須要爲多個元素定義相一樣式的時候,咱們能夠考慮使用繼承的作法)函數
Sass學習
.block { margin: 10px 5px; padding: 2px; } p { @extend .block; /* Inherit styles from '.block' */ border: 1px solid #EEE; } ul, ol { @extend .block; /* Inherit styles from '.block' */ color: #333; text-transform: uppercase; }
Lessspa
.block { margin: 10px 5px; padding: 2px; } p { .block; /* Inherit styles from '.block' */ border: 1px solid #EEE; } ul, ol { .block; /* Inherit styles from '.block' */ color: #333; text-transform: uppercase; } 和混入比較像
四、引入code
Sass 和 Less 關於導入是同樣的
@ import "reset.css"; @ import "file.{type}"; p { background: #0982C1; }
四、顏色函數
Sass
lighten($color, 10%); /* returns a color 10% lighter than $color */ darken($color, 10%); /* returns a color 10% darker than $color */ saturate($color, 10%); /* returns a color 10% more saturated than $color */ desaturate($color, 10%); /* returns a color 10% less saturated than $color */ grayscale($color); /* returns grayscale of $color */ complement($color); /* returns complement color of $color */ invert($color); /* returns inverted color of $color */ mix($color1, $color2, 50%); /* mix $color1 with $color2 with a weight of 50% */
完整的列表請看 Sass Documentation.
$color: #0982C1; h1 { background: $color; border: 3px solid darken($color, 50%); }
Less
lighten(@color, 10%); /* returns a color 10% lighter than @color */ darken(@color, 10%); /* returns a color 10% darker than @color */ saturate(@color, 10%); /* returns a color 10% more saturated than @color */ desaturate(@color, 10%); /* returns a color 10% less saturated than @color */ spin(@color, 10); /* returns a color with a 10 degree larger in hue than @color */ spin(@color, -10); /* returns a color with a 10 degree smaller hue than @color */ mix(@color1, @color2); /* return a mix of @color1 and @color2 */
完整的列表請看 LESS Documentation.
@color: #0982C1; h1 { background: @color; border: 3px solid darken(@color, 50%); }
文章轉載自別人,僅供本人學習使用,禁止轉載