• scss常用语法


    在线编译 https://wow.techbrood.com/fiddle/11143

    群组选择器的嵌套【编译前】

    .container {
      h1, h2, h3 {margin-bottom: .8em}
    }
    

    编译后

    .container h1, .container h2, .container h3 { margin-bottom: .8em }
    

    1. 优先使用scss中的变量

    $biancolor:#ccc;
    
    #deno{
      color:$biancolor
    }
    

    说明

    在scss中使用变量用$符号开头;
    为什么我们要使用scss中的变量。
    比如我们需要动态去切换主题的颜色,
    我们就非常有必要去使用变量了哈。
    这个虽然大家都会,但是在项目中就不一定回去使用变量了。
    

    2.嵌套伪类:通过"&"实现 在中使用的":"符号 添加& 字符号

    #deno{
      .deo1{
        background-color: #ccc;
        &:hover{
          color:red
        }
      }
    }
    

    编译后的

    #deno .deo1 {
      background-color: #ccc;
    }
    #deno .deo1:hover {
      color: red;
    }
    
    

    3. @mixin 和 @include的使用

     @mixin 和 @include在项目中真的是超好用
     当我们某一段css样式大量重复的时候,我们就可以了。
     如果说:我们自定义的滚动条
    

    编译前

    //使用@mixin来定义共同的样式
    @mixin test{
      100px;
      height:100px;
      background:red
    }
    
    // @include 来使用
    #deno{
      @include test()
    }
    

    编译后

    #deno {
       100px;
      height: 100px;
      background: red;
    }
    
    

    4.传参 编译前

    使用传递会让我们的css代码更加的灵活。
    这样写起来会更加的高效
    
    @mixin test($w,$h, $color){
      $w;
      height:$h;
      background:$color
    };
    
    #deno{
      @include test(200px,200px,pink);
    }
    

    编译后

    #deno {
       200px;
      height: 200px;
      background: pink;
    }
    

    5. 默认传参

    @mixin test($w:100px,$h:100px){
      $w;
      height:$h;
      background-color:red;
    }
    #deno{
      @include test(200px,200px);
    }
    

    默认参数 编译前

    <!-- 默认参数优先放置在最后 -->
    @mixin test($color,$size: 20px  ) {
        background: $color;
        font-size: $size;
    }
    #deno {
        @include test(
            $color: green
        )
    }
    

    编译后

    #deno {
      background: green;
      font-size: 20px;
    }
    

    传参(指定参数) 这一种很有用

    
    @mixin test($color,$size: 20px ,$w:100px ) {
        background: $color;
        font-size: $size;
        $w
    }
    #deno {
        @include test(
            $color: green,
            $w:200px
        )
    }
    

    条件判断

    @mixin xingzhaung($x){
      @if($x==zhengfang){
        200px;
        height:200px;
        background: #000;
      }@else{
        100px;
        height:200px;
        background: pink;
      }
    }
    
    div {
      @include xingzhaung(zhengfang)
    }
    
    使用条件判断的时候,需要注意几点。
    第一点就是需要添加 @符号
    第二是: @mixin(函数方法理解为) 要在  @include(方法调用)之前
    他们的位置千万不要颠倒了
    否者会出问题,这个是第一个
    

    条件语句的应用

    比如说:滚动条样似的修改
    超出几行隐藏显示省略号
    字体大小、颜色这些都可以封装成为一个函数,直接使用就ok了哈
    

    个人理解

    在项目中,个人非常推荐去使用scss
    scss在项目中最主要的就是这几个,但是很常用
    如果小伙伴们在scss中发现了其他有趣的东西,欢迎评论
    
    作者:明月人倚楼
    出处:https://www.cnblogs.com/IwishIcould/

    想问问题,打赏了卑微的博主,求求你备注一下的扣扣或者微信;这样我好联系你;(っ•̀ω•́)っ✎⁾⁾!

    如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,或者关注博主,在此感谢!

    万水千山总是情,打赏5毛买辣条行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主(っ•̀ω•́)っ✎⁾⁾!

    想问问题,打赏了卑微的博主,求求你备注一下的扣扣或者微信;这样我好联系你;(っ•̀ω•́)っ✎⁾⁾!

    支付宝
    微信
    本文版权归作者所有,欢迎转载,未经作者同意须保留此段声明,在文章页面明显位置给出原文连接
    如果文中有什么错误,欢迎指出。以免更多的人被误导。
  • 相关阅读:
    org.apache.ibatis.binding.BindingException: Parameter 'username' not found. Available parameters are [0, 1, param1, param2]
    在Springboot中Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]问题
    Springcould学习总结
    XXl-job基于springbooot的基本配置
    Nginx反向代理简单配置
    redis哨兵机制及配置
    redis的主从复制
    jedis在Java环境操作redis
    liunx环境redis的安装
    express之cookie和session
  • 原文地址:https://www.cnblogs.com/IwishIcould/p/15231730.html
Copyright © 2020-2023  润新知