123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- @import './reset.scss';
- //$定义变量 都放在顶部
- $bgColor: #000;
- $keyName: 'color';
- $whiteColor: #eee;
- /*
- div 元素
- 多行注释 编译后 .css文件中会保留
- */
- /*!
- 强制显示 编译后 .min.css文件中 会保留
- */
- div{
- background: $bgColor;
- //#{变量} 差值语句 属性名如果是变量 可以使用
- //一般不建议这样操作
- #{$keyName}: #eee;
- width: 100px;
- }
- //选择器嵌套
- #list{
- width: 100px;
- height: 20px;
- li{
- font-size: 12px;
- p{
- // padding-top: 30px;
- // padding-left: 10px;\
- //属性嵌套 : 和 { 之间要有一个空格
- padding: {
- top: 30px;
- left: 10px;
- }
- }
- }
- //引用父元素选择器
- &-inner{
- color: $bgColor;
- }
- }
- .link{
- color: $bgColor;
- &:hover {
- color: #eee;
- }
- }
- // .login-btn{
- // width: 100px;
- // height: 40px;
- // line-height: 40px;
- // text-align: center;
- // border-radius: 5px;
- // color: $whiteColor;
- // background: $bgColor;
- // }
- // .submit-btn{
- // width: 50px;
- // height: 50px;
- // line-height: 50px;
- // text-align: center;
- // border-radius: 5px;
- // color: $whiteColor;
- // background: $bgColor;
- // }
- //定义一个混合宏
- //定义的时候可以带参数 参数可以设定默认值
- @mixin logo-btn($width:20px,$height:20px,$lineHeight:20px){
- width: $width;
- height: $height;
- line-height: $lineHeight;
- 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,50px ,50px )
- }
- .del-btn{
- @include logo-btn()
- }
- //调用 混合宏 传参 可以指定参数的名字和数值
- .aa-btn{
- @include logo-btn($width: 300px)
- }
- .wrapper{
- width: 100px;
- height: 100px;
- font-size: 10px;
- .inner{
- //@extend 继承某一个选择器的样式
- //编译的时候 会将相同的样式 转化成分组选择器
- //如果继承的选择器 有子选择器 会继承过来
- @extend .wrapper;
- padding: 20px;
- }
- }
- #main{
- @extend .wrapper;
- margin: 10px;
- }
- /*
- 绝对值: abs(-10px)
- 四舍五入:round(5.5)
- 向上取整:ceil(5.5)
- 向下取整:floor(5.5)
- 百分比:percentage(30px / 100px)
- 最小值: min(1,2,3)
- 最大值:max(1,2,3)
- */
- $width: 6;
- .content{
- width: percentage(30px / 100px);
- }
- //定义函数
- @function changeWidth($width){
- @return $width * 2
- }
- div{
- width: changeWidth(30px);
- }
- $list: 1px solid #000;
- $colorList: blue,red,yellow;
- p{
- border: $list;
- //nth($list,index)获取列表第几项
- background: nth($colorList,3);
- }
- //@if 指令 与js相同
- $length: 0;
- li{
- @if $length < 1{
- font-size: 12px;
- } @else if $length > 1 and $length < 4{
- font-size: 10px;
- } @else {
- font-size: 2px;
- }
- }
- //@for 类似于js中的for循环
- //through 包括
- @for $i from 1 through 3{
- .list-#{$i}{
- width: $i * 100px;
- }
- }
- //to 不包括
- @for $i from 1 to 3{
- .none-#{$i}{
- width: $i * 50px;
- }
- }
|