美文网首页
scss语法简单总结

scss语法简单总结

作者: 胡萝卜樱 | 来源:发表于2017-07-17 14:10 被阅读0次

    Variables(声明变量)

    [SCSS SYNTAX]
    
    $font-stack:    Helvetica, sans-serif;
    $primary-color: #333;
    
    body {
      font: 100% $font-stack;
      color: $primary-color;
    }
    
    -----------------
    
    [CSS LIKE]
    
    body {
      font: 100% Helvetica, sans-serif;
      color: #333;
    }
    

    Nesting(嵌套)

    [SCSS SYNTAX]
    
    nav {
      ul {
        margin: 0;
        padding: 0;
        list-style: none;
      }
    
      li { display: inline-block; }
    
      a {
        display: block;
        padding: 6px 12px;
        text-decoration: none;
      }
    }
    
    -------------------------
    
    [CSS LIKE]
    
    nav ul {
      margin: 0;
      padding: 0;
      list-style: none;
    }
    
    nav li {
      display: inline-block;
    }
    
    nav a {
      display: block;
      padding: 6px 12px;
      text-decoration: none;
    }
    

    Partials

    
    

    Import(引入其他样式)

    [SCSS SYNTAX]
    
    // _reset.scss
    
    html,
    body,
    ul,
    ol {
      margin:  0;
      padding: 0;
    }
    
    
    // base.scss
    
    @import 'reset';
    
    body {
      font: 100% Helvetica, sans-serif;
      background-color: #efefef;
    }
    
    
    --------------------
    
    [CSS LIKE]
    
    html, body, ul, ol {
      margin: 0;
      padding: 0;
    }
    
    body {
      font: 100% Helvetica, sans-serif;
      background-color: #efefef;
    }
    

    Mixins

    [SCSS SYNTAX]
    
    @mixin border-radius($radius) {
      -webkit-border-radius: $radius;
         -moz-border-radius: $radius;
          -ms-border-radius: $radius;
              border-radius: $radius;
    }
    
    .box { @include border-radius(10px); }
    
    ---------------------
    
    [CSS LIKE]
    
    .box {
      -webkit-border-radius: 10px;
      -moz-border-radius: 10px;
      -ms-border-radius: 10px;
      border-radius: 10px;
    }
    
    

    Extend/Inheritance(继承样式)

    [SCSS SYNTAX]
    
    .message {
      border: 1px solid #ccc;
      padding: 10px;
      color: #333;
    }
    
    .success {
      @extend .message;
      border-color: green;
    }
    
    .error {
      @extend .message;
      border-color: red;
    }
    
    .warning {
      @extend .message;
      border-color: yellow;
    }
    
    ---------------------------
    
    [CSS LIKE]
    
    .message, .success, .error, .warning {
      border: 1px solid #cccccc;
      padding: 10px;
      color: #333;
    }
    
    .success {
      border-color: green;
    }
    
    .error {
      border-color: red;
    }
    
    .warning {
      border-color: yellow;
    }
    

    Operators(加减乘除操作)

    [SCSS SYNTAX]
    
    .container { width: 100%; }
    
    
    article[role="main"] {
      float: left;
      width: 600px / 960px * 100%;
    }
    
    aside[role="complementary"] {
      float: right;
      width: 300px / 960px * 100%;
    }
    
    --------------------
    
    [CSS LIKE]
    
    .container {
      width: 100%;
    }
    
    article[role="main"] {
      float: left;
      width: 62.5%;
    }
    
    aside[role="complementary"] {
      float: right;
      width: 31.25%;
    }
    
    

    相关文章

      网友评论

          本文标题:scss语法简单总结

          本文链接:https://www.haomeiwen.com/subject/kxgfkxtx.html