关于scss:使用scss制作按钮变亮变暗效果
演示失常状态鼠标悬浮状态点击状态演示为第一个区域(红色按钮) front在咱们进行前端开发时,如果用纯CSS实现这种鼠标悬浮时变深,点击变浅很容易(:hover,:focus),然而数量一多,写起来就十分恶心,所以咱们能够用scss来实现这种成果。 scss-codes.all{ //通用属性 width: 60px; height: 60px; margin: 20px; display: inline-block; border-radius: 10px; outline: none; //禁止点击时呈现外边 border: none; //禁止边框}$list: rgb(255, 0, 0),rgb(255, 217, 0),rgb(0, 38, 255),rgb(0, 255, 255); //色彩数组,能够应用HEX,rgb,这里最好不要用rgba@for $i from 1 through 4{ //through后的数字是要创立div的个数 .ml-#{$i}{ //如ml-1,ml-2,ml-3 @extend .all; //继承.all font-size: 10px * $i; background-color: nth($list,$i); //设置默认背景色彩,此处会调用色彩数组中对应的色彩 color: white; transition: all 0.3s; //增加动画成果 $color: nth($list,$i); //将对应色彩创立变量$color,避免出现反复语句 &:hover{ //鼠标悬浮 background: darken($color,20%); //亮度减淡20% } &:active{ //鼠标点击 background: lighten($color,20%); //亮度晋升20% } }}css-codes编译后的后果: ...