scss基础用法

  • html

    <div class="main ">
        <div class="top"></div>
        <div class="center"></div>
        <div class="bottom"></div>
    </div>
    
  1. 嵌套

    1. 嵌套标签

      .main {
          .top {
              background: red;
          }
      }
      相当于css的
      .main .top
      
    2. 嵌套属性

       .font {
           family: Helvetica, sans-serif;
           size: 18px;
           weight: bold;
       }
       
       上面的scss代码相当于下面的css代码
       font-family: Helvetica, sans-serif;
       font-size: 18px;
       font-weight: bold;
       
      
  2. 变量和运算操作符

    变量可包括(字符串、数字、颜色值、布尔值、列表、null值)

    wrapperWidth: 500;
    wripperHeight: 500;
    $nomalWidth: 100;
    $nomalHeight: 100;
    .main {
        width: wrapperWidth;
        height: wripperHeight;
        .top {
            background: red;
            width: wrapperWidth * 0.2; //可以进行加减乘除运算
            height: nomalHeight;
        }
    }
    
  3. 混合

    @mixin相当于定义了函数,使用时需用@include(参数)

    @mixin setheight($property) {
        height:$property;
        width:$property;
     }
    
    .main {
        background-color: $mainColor;
        border: 1px solid #000000;
        @include setheight(500) 
        .top {
            background-color: $topColor;
            @include setheight(100) 
        }
        .center {
            background-color: $topColor;
            @include setheight(100) 
        }
        .bottom {
            background-color: $topColor;
            @include setheight(100) 
        }
    }
    
  4. 继承

    如果一个样式与另外一个样式几乎相同,只有少量的区别,则使用 @extend,使一个选择器的样式从另一选择器继承

    .common {
       width: 100;
       height: 100;
    }
    .main {
       .top {
           width: 100;
           height: 100;
           background-color: red
       }
       .center {
          @extend .top;
           background-color: blue;
       }
       .bottom {
          @extend .top;
           background-color: green; 
       }
    }
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 作为Web前端基础的三大重要组成部分之一的CSS,它主要用于设置HTML页面中的文本内容(字体、大小、对齐方式等)...
    浅浅而谈阅读 1,265评论 0 0
  • 1. 浏览器页面有哪三层构成?分别是什么?作用是什么?构成:结构层、表示层、行为层。分别是:HTML、CSS、Ja...
    生软今天解散了吗阅读 466评论 0 0
  • 1 注释规范 2 缩进/空格/换行规范 每个缩进使用4个空格,不允许使用 2 个空格 或 tab//正确.samp...
    壹枕星河阅读 637评论 0 0
  • 一.CSS描述 CSS全称为“层叠样式表(Cascading Style Sheets)”,它主要是用于定义HTM...
    snowy_sunny阅读 1,109评论 0 4
  • 1 介绍一下标准的CSS的盒子模型?与低版本IE的盒子模型有什么不同的? 标准盒子模型:宽度=内容的宽度(cont...
    HelloJames阅读 329评论 0 3