scss开发常见基本用法总结

test.scss文件


*{
  margin: 0;
  padding: 0;
}

// 变量的声明
$width:500px;
$height:500px;
$bg-color:#000;

// 混合器的使用
@mixin common($w:null,$h:null,$bg:null) {
  width: $w;
  height: $h;
  background-color: $bg;
}

//兼容各个浏览器
@mixin autoprefix($name, $t) {
  -webkit-#{$name}: $t;
  -moz-#{$name}: $t;
  -o-#{$name}: $t;
    #{$name}: $t;
}

@mixin common1{
  // display: flex;
  // justify-content: space-between;
  @include autoprefix(display,flex);
  @include autoprefix(justify-content,space-between);
}

// 选择器继承来精简CSS
.commonp{
  @include common(100px,100px,yellow);
}

//媒体查询
@mixin medias($media,$color){
  @media #{$media}{
    @include common(null,null,$color);
  } 
}

.name{
  //混入
  @include common($width,$height,$bg-color);
  @include common1;
  @include medias((min-width:0) and(max-width:768px),red);
  @include medias((min-width:769px),rgb(229, 255, 0));

  &-p{
    //继承css
    @extend .commonp;
  }

  &-p1{
    //继承css
    @extend .commonp;
  }
}

.space{
  @include autoprefix(display,flex);
  @include common(100%,300px,rgb(0, 255, 149));
  @include medias((min-width:0) and(max-width:768px),rgb(47, 0, 255));
  @include medias((min-width:769px),rgb(187, 255, 0));

  &-p{
    @include common(80px,80px,rgb(23, 26, 25));
    @include autoprefix(align-self,flex-end);
  }

  &-p1{
    @include common(80px,80px,rgb(47, 33, 170));
    @include autoprefix(align-self,flex-start);
  }
}

test.scss生成对应test.css文件

* {
  margin: 0;
  padding: 0;
}

.commonp, .name-p, .name-p1 {
  width: 100px;
  height: 100px;
  background-color: yellow;
}

.name {
  width: 500px;
  height: 500px;
  background-color: #000;
  -webkit-display: flex;
  -moz-display: flex;
  -o-display: flex;
  display: flex;
  -webkit-justify-content: space-between;
  -moz-justify-content: space-between;
  -o-justify-content: space-between;
  justify-content: space-between;
}

@media (max-width: 768px) {
  .name {
    background-color: red;
  }
}

@media (min-width: 769px) {
  .name {
    background-color: #e5ff00;
  }
}

.space {
  -webkit-display: flex;
  -moz-display: flex;
  -o-display: flex;
  display: flex;
  width: 100%;
  height: 300px;
  background-color: #00ff95;
}

@media (max-width: 768px) {
  .space {
    background-color: #2f00ff;
  }
}

@media (min-width: 769px) {
  .space {
    background-color: #bbff00;
  }
}

.space-p {
  width: 80px;
  height: 80px;
  background-color: #171a19;
  -webkit-align-self: flex-end;
  -moz-align-self: flex-end;
  -o-align-self: flex-end;
  align-self: flex-end;
}

.space-p1 {
  width: 80px;
  height: 80px;
  background-color: #2f21aa;
  -webkit-align-self: flex-start;
  -moz-align-self: flex-start;
  -o-align-self: flex-start;
  align-self: flex-start;
}

test.html测试

<div class="name">
      <p class="name-p"></p>
      <p class="name-p1"></p>
  </div>

  <div class="space">
    <p class="space-p"></p>
    <p class="space-p1"></p>
  </div>  ```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

追逐梦想之路_随笔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值