Sass/Scss学习笔记

2020-01-07  本文已影响0人  DorangeWang

Sass version 1.24.0

// 当行注释 slient comment 不会生成到css中
/* 多行注释 loud comment */
html{
  font-size: 14px;
  color: #ccc;
}
@charset "UTF-8";
/* 多行注释 loud comment */
html {
  font-size: 14px;
  color: #ccc;
}
$font-size: 14px;
body{
  font-size: $font-size;
}
body {
  font-size: 14px;
}
body{
  $bg-color: #ddd;
  background-color: $bg-color;
}
body {
  background-color: #ddd;
}
$font-size: 14px;
body{
  font-size: $font-size;
  line-height: #{$font-size};
}
body {
  font-size: 14px;
  line-height: 14px;
}
$color-info: #909399;
.nav {
  ul {
    padding: 0;
    margin: 0;
    > li {
      list-style: none; 
      border-bottom: 1px solid #ddd; 
      &:last-child {
        border: none;
      }
      &:hover{
        background-color: $color-info;
      }
    }
  }
}
.nav ul {
  padding: 0;
  margin: 0;
}
.nav ul > li {
  list-style: none;
  border-bottom: 1px solid #ddd;
}
.nav ul > li:last-child {
  border: none;
}
.nav ul > li:hover {
  background-color: #909399;
}
.nav {
  ul {
    padding: 0;
    margin: 0;
    > li {
      list-style: none; 
      border-bottom: 1px solid #ddd; 
    }
  }
  body & {
    padding: 0;
    margin: 0;
  }
  &__list{
    position: relative;
  }
}
.nav ul {
  padding: 0;
  margin: 0;
}
.nav ul > li {
  list-style: none;
  border-bottom: 1px solid #ddd;
}
body .nav {
  padding: 0;
  margin: 0;
}
.nav__list {
  position: relative;
}
$font-size: 14px;
$color-success: #67C23A;
$color-warning: #E6A23C;
.tips {
  font-size: $font-size;
}
.tips-success {
  @extend .tips;
  color: $color-success;
}
.tips-warning {
  @extend .tips;
  color: $color-warning;
}
.tips, .tips-warning, .tips-success {
  font-size: 14px;
}

.tips-success {
  color: #67C23A;
}

.tips-warning {
  color: #E6A23C;
}
$color-primary: #409EFF;
$color-danger: #F56C6C;
%btn{
  height: 50px;
  width: 200px;
  border-radius: 5px;
}
.btn-primary{
  @extend %btn;
  background-color: $color-primary;
  color: #fff;
}
.btn-danger{
  @extend %btn;
  background-color: $color-danger;
  color: #fff;
}
.btn-danger, .btn-primary {
  height: 50px;
  width: 200px;
  border-radius: 5px;
}

.btn-primary {
  background-color: #409EFF;
  color: #fff;
}

.btn-danger {
  background-color: #F56C6C;
  color: #fff;
}
@mixin square($size, $radius: 0) {
  width: $size;
  height: $size;
  @if $radius != 0 {
    border-radius: $radius;
  }
}
.avatar {
  @include square(100px, $radius: 4px)
}
.avatar {
  width: 100px;
  height: 100px;
  border-radius: 4px;
}
@function transNums($num1, $num2){
  @return ($num1 + $num2)/2;
}
.container{
  font-size: transNums(12px, 24px);
}
.container {
  font-size: 18px;
}
// _common.scss
$bg-color: #ffffff;
@mixin full {
  height: 100%;
  width: 100%;
}
// mian.scss
@use 'common';
.wrap{
  @include common.full;
  background-color: common.$bg-color;
  font-size: 14px;
}
.wrap {
  height: 100%;
  width: 100%;
  background-color: #ffffff;
  font-size: 14px;
}
$color-primary: #409EFF;
$color-success: #67C23A;
$color-warning: #E6A23C;
$color-danger: #F56C6C;
$color-info: #909399;
@mixin theme ($color: primary){
  @if $color == success {
    color: $color-success;
  } @else if $color == warning {
    color: $color-warning;
  } @else if $color == warning {
    color: $color-warning;
  } @else if $color == danger {
    color: $color-danger;
  } @else if $color == info {
    color: $color-info;
  } @else {
    color: $color-primary;
  }
}
.tips {
  @include theme(danger)
}
.tips {
  color: #F56C6C;
}
$sizes: 40px, 50px, 80px;
@each $size in $sizes {
  .icon-#{$size} {
    font-size: $size;
    height: $size;
    width: $size;
  }
}
.icon-40px {
  font-size: 40px;
  height: 40px;
  width: 40px;
}
.icon-50px {
  font-size: 50px;
  height: 50px;
  width: 50px;
}
.icon-80px {
  font-size: 80px;
  height: 80px;
  width: 80px;
}
@for $i from 1 through 3 {
  .mgr#{$i*10}{
    margin-right: $i * 10px;
  }
}
.mgr10 {
  margin-right: 10px;
}
.mgr20 {
  margin-right: 20px;
}
.mgr30 {
  margin-right: 30px;
}
.box1{
  width: 100 / 200 * 100%;
}
.box2{
  width: 100px / 200px * 90%;
}
.box1 {
  width: 50%;
}
.box2 {
  width: 45%;
}

上一篇下一篇

猜你喜欢

热点阅读