sass基础语法

变量

$width: 300px; // 定义一个变量

width: $width; // 使用定义的变量

$str: 'hello.jpeg'; 

background-image: url('./img/'+$str); // 使用+拼接

background-image: url('./img/#{$str}'); // 使用#{}拼接

数据类型

$width: 300px;

/*number*/
.div {
  width: $width;
}

$color: #ffe932;

/*color*/
.div {
  background-color: $color;
}

$str: 'hello.jpeg';
$strClass: 'hello';

/*string*/
.div.#{$strClass} {
  background-image: url('./img/'+$str);
}

$list:(100px, 200px, 300px, 400px);

/*list*/
.div {
  width: nth($list, 1); // 返回list的第一个值,即100px(从1开始计数)
  zoom: index($list, 100px); // 返回参数出现的位置,即1
  margin: join($list); // 设置4个位置的margin
}

$map: (top: 1px, left: 2px, bottom: 3px, right: 4px);

/*map*/
.div {
  top: map-get($map, top); // 返回键为top的值
  bottom: map-get($map, bottom); // 返回键为bottom的值
}

计算功能

$num1: 100px;
$num2: 200px;
$width: $num1+$num2;

/*加减乘除*
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值