zoukankan      html  css  js  c++  java
  • sass基本语法

    ## sass基本语法 ##

        选择器嵌套:

            <nav> 
                <ul> 
                     <li><a href="#">Home</a></li> 
                     <li><a href="#">Haml</a></li> 
                </ul>
            </nav>
            
            nav{
                display:block;
                ul{
                    margin:50px auto;
                    &:before,&:after{
                        content:"";
                        display:table;
                    }
                    li{
                        float:left;
                        &:hover{
                            backgroundL#000
                        }
                        a{
                            padding:1em 2em;
                        }
                    }
                }
            }

        css属性嵌套:

            css原样式
            a {
                text-transform: uppercase;
                text-decoration: none; 
                font-family: Arial,Helvetica; 
                font-size: 14px;
            }
            sass改写
            a {
                text:{
                    transform: uppercase;
                    decoration: none; 
                }
                font:{
                    family: Arial,Helvetica;
                    size: 14px;
                }
            }

        定义变量及数值计算:

            $red:'red';
            $border:5;
            .red{
                color:$red;
            }
            .border{
                top:20px+30px;  //可以直接运算
                margin-top:#{$border*$border}px //变量可以乘不能加
                border:solid #{$border}px $red;  //使用#{}进行混合编译,组合变量与px等字符
            }

        继承功能:

            .a1{
                color:blue;
            }
            .a2{
                @extend .a1;   //复用a1的样式
                font-size:#{$num}px
            }
            //通过mixin传值继承
            @mixin center($f){
                text-align:$f;
            }
            .border{
                @include center(center) //调用mixin函数
            }

        插入其他文件:

            先创建test.scss文件
            @import "./test.scss";  //在需要导入的文件中添加上了test.scss中的样式

        条件语句:

            $red:'red';
            $green:'green';
            @mixin bgColor($b){
                @if($b==5){
                    background-color:#{$red};
                }@else if($b==6){
                    background-color:#{$green};
                }@else{
                    background-color:blue;
                }
            }

        循环语句:

            @for $i from 1 to 5{
                .a#{$i}{ //循环类名
                    background-image:url("images/#{$i}.png")
                }
            }
            @each $k in 1,2,3,4{
                .c#{$k}{ 
                    background-image:url("images/#{$k}.png")
                }    
            }  

        函数:

            @function colorrgba($r,$g,$b,$a){
                @return rgba($r,$g,$b,$a);
            }
            .border{
                color:colorrgba(112,112,145,0.6)
            }

  • 相关阅读:
    编程命名规范
    python 字符串编解码介绍
    django之sqlite3常见错误
    asp.net请求过程文章推荐
    python 多线程的文章
    工作中处理文本的python代码片段
    memcached一些知识
    咱计算机专业的人,能不能不那么特别地彰显对语文的无知?——再谈面向对象...
    你真的了解分层架构吗?——写给被PetShop"毒害"的朋友们...
    混蛋的面试题——《大话设计模式》读后感
  • 原文地址:https://www.cnblogs.com/Tabb/p/9261946.html
Copyright © 2011-2022 走看看