더 적은

WBOY
WBOY원래의
2016-09-29 09:19:051115검색
<span style="color: #008080;"> 1</span> <span style="color: #000000;">使用 @ 定义变量
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">    变量可以做运算
</span><span style="color: #008080;"> 3</span>     
<span style="color: #008080;"> 4</span> <span style="color: #000000;">    @color : #000;
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">    @width : 1000px;
</span><span style="color: #008080;"> 6</span>     
<span style="color: #008080;"> 7</span> <span style="color: #000000;">使用 & 表示当前类
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">    .box{
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">        &:hover{
</span><span style="color: #008080;">10</span> <span style="color: #000000;">            color : #000;
</span><span style="color: #008080;">11</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">12</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">13</span> 
<span style="color: #008080;">14</span> <span style="color: #000000;">css 可以嵌套
</span><span style="color: #008080;">15</span> 
<span style="color: #008080;">16</span> <span style="color: #000000;">    ul{
</span><span style="color: #008080;">17</span> <span style="color: #000000;">        display : block;
</span><span style="color: #008080;">18</span> <span style="color: #000000;">        li{
</span><span style="color: #008080;">19</span> <span style="color: #000000;">            float : left;
</span><span style="color: #008080;">20</span> <span style="color: #000000;">            a{
</span><span style="color: #008080;">21</span> <span style="color: #000000;">                font-size : 18px;
</span><span style="color: #008080;">22</span> <span style="color: #000000;">            }
</span><span style="color: #008080;">23</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">24</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">25</span> 
<span style="color: #008080;">26</span> <span style="color: #000000;">继承 : 直接在需要的地方引用 class或者 id 类
</span><span style="color: #008080;">27</span> 
<span style="color: #008080;">28</span> <span style="color: #000000;">.clearfix{
</span><span style="color: #008080;">29</span> <span style="color: #000000;">    zoom : 1;
</span><span style="color: #008080;">30</span> <span style="color: #000000;">    display : block;
</span><span style="color: #008080;">31</span> <span style="color: #000000;">    &:after{
</span><span style="color: #008080;">32</span> <span style="color: #000000;">        content: "";
</span><span style="color: #008080;">33</span> <span style="color: #000000;">        visibility: hidden;
</span><span style="color: #008080;">34</span> <span style="color: #000000;">        clear: both;
</span><span style="color: #008080;">35</span> <span style="color: #000000;">        height: 0;
</span><span style="color: #008080;">36</span> <span style="color: #000000;">        display: block;
</span><span style="color: #008080;">37</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">38</span> <span style="color: #000000;">}
</span><span style="color: #008080;">39</span> 
<span style="color: #008080;">40</span> <span style="color: #000000;">.radius(@radius : 15px){
</span><span style="color: #008080;">41</span> <span style="color: #000000;">    border-radius: @radius;
</span><span style="color: #008080;">42</span> <span style="color: #000000;">}
</span><span style="color: #008080;">43</span> 
<span style="color: #008080;">44</span> <span style="color: #000000;">.box{
</span><span style="color: #008080;">45</span> <span style="color: #000000;">    .clearfix;
</span><span style="color: #008080;">46</span> <span style="color: #000000;">    .radius(10px);
</span><span style="color: #008080;">47</span> <span style="color: #000000;">}
</span><span style="color: #008080;">48</span> 
<span style="color: #008080;">49</span> <span style="color: #000000;">混合 : 类似 js 中的函数, [或者叫继承]
</span><span style="color: #008080;">50</span> <span style="color: #000000;">.layout(){
</span><span style="color: #008080;">51</span> <span style="color: #000000;">    ...
</span><span style="color: #008080;">52</span> <span style="color: #000000;">}
</span><span style="color: #008080;">53</span> 
<span style="color: #008080;">54</span> 
<span style="color: #008080;">55</span> <span style="color: #000000;">作用域 : 限制继承的条件,可以继承一个 类的部分内容
</span><span style="color: #008080;">56</span> 
<span style="color: #008080;">57</span> <span style="color: #000000;">延伸 : &:extend(.box); 括号中可以填写多个 类名  编译后的效果就是 css 中的分组
</span><span style="color: #008080;">58</span> 
<span style="color: #008080;">59</span> 
<span style="color: #008080;">60</span> <span style="color: #000000;">when 用来做条件判断
</span><span style="color: #008080;">61</span> 
<span style="color: #008080;">62</span> <span style="color: #000000;">when not 不等于
</span><span style="color: #008080;">63</span> 
<span style="color: #008080;">64</span> <span style="color: #000000;">/*
</span><span style="color: #008080;">65</span> <span style="color: #000000;">    使用 isnumber 来判断某个参数是否为 数字
</span><span style="color: #008080;">66</span> <span style="color: #000000;"> * */
</span><span style="color: #008080;">67</span> 
<span style="color: #008080;">68</span> <span style="color: #000000;">.border(@width : 1px , @style : solid, @color : #d1d1d1) when (isnumber(@width)){
</span><span style="color: #008080;">69</span> <span style="color: #000000;">    border: @width @style @color;
</span><span style="color: #008080;">70</span> <span style="color: #000000;">}
</span><span style="color: #008080;">71</span> 
<span style="color: #008080;">72</span> <span style="color: #000000;">/*
</span><span style="color: #008080;">73</span> <span style="color: #000000;">    使用 iscolor 来判断某个参数是否为 颜色
</span><span style="color: #008080;">74</span> <span style="color: #000000;"> * */
</span><span style="color: #008080;">75</span> 
<span style="color: #008080;">76</span> <span style="color: #000000;">.border(@color) when (iscolor(@color)){
</span><span style="color: #008080;">77</span>     
<span style="color: #008080;">78</span> <span style="color: #000000;">    .border(1px , solid , @color);
</span><span style="color: #008080;">79</span> <span style="color: #000000;">}
</span><span style="color: #008080;">80</span> 
<span style="color: #008080;">81</span> 
<span style="color: #008080;">82</span> <span style="color: #000000;">.border(@solid) when not ( iscolor(@solid)) , ( isnumber(@solid) ){
</span><span style="color: #008080;">83</span> <span style="color: #000000;">    .border(1px , @solid);
</span><span style="color: #008080;">84</span> }

변수를 정의하려면 @를 사용하세요. 변수는 작업을 수행할 수 있습니다. @color: #000;@width: 1000px; 현재 클래스를 나타내려면 &를 사용하세요.{&:hover{color: #000;}}
css는 중첩됨
ul{display : block;li{float : left;a{font-size : 18px;}}}
상속: 필요한 경우 클래스 또는 ID 클래스를 직접 참조
.clearfix{zoom : 1;display:block;&:after{content: ""; 가시성: 숨김; 모두 높이: 0; 디스플레이: 블록;}}
.radius(@radius: 15px) radius;}
.box{.clearfix;.radius(10px);}
혼합: js의 함수와 유사 [또는 상속].layout(){...}

범위 : 상속 조건을 제한하면 클래스의 일부를 상속할 수 있습니다.
확장: &:extend(.box); 여러 클래스 이름을 괄호 안에 채울 수 있습니다. 컴파일된 효과는 CSS에서

그룹화됩니다.
와 같지 않을 때 조건부 판단
/* 매개변수가 숫자인지 판단하려면 isnumber를 사용하세요. */
.border(@width: 1px, @style: solid, @color: #d1d1d1 ) when (isnumber(@width)){ border: @width @style @color;}
/* iscolor를 사용하여 매개변수가 색상인지 확인 * */
.border(@color) when (iscolor (@color)){ .border(1px, solid, @color);}

.border(@solid) 그렇지 않은 경우 ( iscolor(@solid)) , ( isnumber(@solid) ){ .border (1px , @solid);}

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.