less and sass

Less

  • 变量

    @width: 10px;
    @height: @width + 10px;
    
    #header {
      width: @width;
      height: @height;
    }
    
  • Mixin

    .bordered {
      border-top: dotted 1px black;
      border-bottom: solid 2px black;
    }
    
    #menu a {
      color: #111;
      .bordered();
    }
    
    .post a {
      color: red;
      .bordered();
    }
    
  • nesting

    #header {
      color: black;
      .navigation {
        font-size: 12px;
      }
      .logo {
        width: 300px;
      }
    }
    

Sass

  • 变量

    SASS允许使用变量,所有变量以$开头。如果变量需要镶嵌在字符串之中,就必须需要写在#{}之中。

      $blue : #1875e7; 
    
      div {
       color : $blue;
      }
      
      $side : left;
    
      .rounded {
        border-#{$side}-radius: 5px;
      }
    
  • 嵌套

    在嵌套的代码块内,可以使用&引用父元素。比如a:hover伪类,可以写成:

      div {
        hi {
          color:red;
        }
      }
      
       p {
        border: {
          color: red;
        }
      }
      
      a {
        &:hover { color: #ffb3ff; }
      }
    
  • 继承 @extend

    .class1 {
        border: 1px solid #ddd;
      }
      
    .class2 {
        @extend .class1;
        font-size:120%;
      }
    
  • Mixin

    Mixin有点像C语言的宏(macro),是可以重用的代码块。

    使用@mixin命令,定义一个代码块。

    使用@include命令,调用这个mixin。

     @mixin left {
        float: left;
        margin-left: 10px;
      }
      
     div {
        @include left;
      }
    

    mixin的强大之处,在于可以指定参数和缺省值。

    @mixin left($value: 10px) {
        float: left;
        margin-right: $value;
      }
       div {
        @include left(20px);
      }
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值