123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- // @import 'max.scss';
- $bgcolor: #ff0000;
- $keyName: 'color';
- $whiteColor: #000000;
- /*
- sass使用 $ 符号来标识变量
- */
- //sass变量可以存储以下信息:字符串、数字
- //、颜色值、布尔值、列表null值
- /*! sass有作用域 */
- /*
- 多行注释 会在css文件里生成 但是不会再min.css文件里生成
- 单行注释 不会在css文件里生成
- 强制注释 会在css和min.css文件里生成
- */
- /*
- 插值语句
- #{变量} 属性名如果是变量可以使用这种
- 一般 不建议这么操作
- */
- div{
- width: 100px;
- height: 100px;
- background: $bgcolor;
- #{$keyName}: $bgcolor;
- }
- div2{
- width: 200px;
- height: 200px;
- background: $bgcolor;
- }
- //选择器的嵌套
- #list{
- width: 100px;
- height: 100px;
- li{
- font-size: 12px;
- p{
- // padding-top: 20px;
- // padding-left: 30px;
- //属性嵌套 : 和 { 中间一定要有一个空格
- padding: {
- top: 20px;
- left: 40px
- }
- }
- }
- //& 引用父选择器
- &-inner{
- color: $bgcolor;
- }
- }
- .link{
- color: $bgcolor;
- &:hover{
- color: #ccc;
- }
- }
- // .login-btn{
- // width: 100px;
- // height: 40px;
- // line-height: 40px;
- // text-align: center;
- // border-radius: 5px;
- // color: $whiteColor;
- // background: $bgcolor;
- // }
- // .submit-btn{
- // width: 50px;
- // height: 20px;
- // line-height: 20px;
- // text-align: center;
- // border-radius: 5px;
- // color: $whiteColor;
- // background: $bgcolor;
- // }
- //定义的一个混合宏
- //定义的时候可以带有参数 参数 也可以设置默认值
- @mixin logo-btn($width: 200px,$height: 100px,$lheight: 100px){
- width: $width;
- height: $height;
- line-height: $lheight;
- text-align: center;
- border-radius: 5px;
- color: $whiteColor;
- background: $bgcolor;
- }
- //通过@include 去调用设置的混合宏
- .login-btn{
- @include logo-btn(100px,40px,40px)
- }
- .submit-btn{
- @include logo-btn(50px,30px)
- }
- .del-btn{
- @include logo-btn()
- }
- .wrapper {
- width: 100px;
- height: 30px;
- font-size: 10px;
- .inner{
- //@extend 继承某一个选择器的样式
- //如果继承的选择器 有子选择器 会一并继承过来
- //编译的时候 会将相同的样式 转化成分组选择器
- @extend .wrapper;
- padding: 20px;
- p{
- color: $bgcolor;
- }
- }
- }
- #main{
- @extend .wrapper;
- margin: 10px
- }
- $width: 5.9px;
- .content{
- // width: ceil($width);
- // height: abs(-10px);
- width: percentage(30 / 100);
- }
- //@function 定义函数
- @function changeWidth($width){
- @return $width * 2
- }
- .last{
- width: changeWidth(4);
- }
- $list: 1px solid #000;
- div{
- width: changeWidth(40px);
- border-top: $list;
- }
- section{
- border-bottom: $list;
- }
- //列表要用逗号分割
- $colorList: red,blue,pink,green;
- p{
- //nth($list,index)通过索引获取列表当中的第index项
- color: nth($colorList,2)
- }
- $length: 2;
- li{
- //@if 指令 (与js中的if效果相同)
- //sass 中的逻辑判断 and or not
- @if $length > 0 and $length < 3{
- font-size: 12px;
- } @else if $length >= 3{
- font-size: 16px;
- }@else{
- font-size: 20px;
- }
- }
- //through 包含3
- @for $i from 1 through 3 {
- .list-#{$i}{
- width: $i * 100px;
- }
- }
- //to 不包含3
- @for $i from 1 to 3{
- .none-#{$i}{
- width: $i * 100px;
- }
- }
- //each in 循环列表
- @each $var in $colorList {
- .content-#{$var}{
- color: $var;
- }
- };
- $a: 3;
- @while $a > 0 {
- .none_#{$a} {
- width: 2px * $a;
- }
- $a: $a - 1;
- }
|