1_style.scss 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. @import './reset.scss';
  2. //$定义变量 都放在顶部
  3. $bgColor: #000;
  4. $keyName: 'color';
  5. $whiteColor: #eee;
  6. /*
  7. div 元素
  8. 多行注释 编译后 .css文件中会保留
  9. */
  10. /*!
  11. 强制显示 编译后 .min.css文件中 会保留
  12. */
  13. div{
  14. background: $bgColor;
  15. //#{变量} 差值语句 属性名如果是变量 可以使用
  16. //一般不建议这样操作
  17. #{$keyName}: #eee;
  18. width: 100px;
  19. }
  20. //选择器嵌套
  21. #list{
  22. width: 100px;
  23. height: 20px;
  24. li{
  25. font-size: 12px;
  26. p{
  27. // padding-top: 30px;
  28. // padding-left: 10px;\
  29. //属性嵌套 : 和 { 之间要有一个空格
  30. padding: {
  31. top: 30px;
  32. left: 10px;
  33. }
  34. }
  35. }
  36. //引用父元素选择器
  37. &-inner{
  38. color: $bgColor;
  39. }
  40. }
  41. .link{
  42. color: $bgColor;
  43. &:hover {
  44. color: #eee;
  45. }
  46. }
  47. // .login-btn{
  48. // width: 100px;
  49. // height: 40px;
  50. // line-height: 40px;
  51. // text-align: center;
  52. // border-radius: 5px;
  53. // color: $whiteColor;
  54. // background: $bgColor;
  55. // }
  56. // .submit-btn{
  57. // width: 50px;
  58. // height: 50px;
  59. // line-height: 50px;
  60. // text-align: center;
  61. // border-radius: 5px;
  62. // color: $whiteColor;
  63. // background: $bgColor;
  64. // }
  65. //定义一个混合宏
  66. //定义的时候可以带参数 参数可以设定默认值
  67. @mixin logo-btn($width:20px,$height:20px,$lineHeight:20px){
  68. width: $width;
  69. height: $height;
  70. line-height: $lineHeight;
  71. text-align: center;
  72. border-radius: 5px;
  73. color: $whiteColor;
  74. background: $bgColor;
  75. }
  76. //通过@include 去调用设置的混合宏
  77. .login-btn{
  78. @include logo-btn(100px,40px ,40px )
  79. }
  80. .submit-btn{
  81. @include logo-btn(50px,50px ,50px )
  82. }
  83. .del-btn{
  84. @include logo-btn()
  85. }
  86. //调用 混合宏 传参 可以指定参数的名字和数值
  87. .aa-btn{
  88. @include logo-btn($width: 300px)
  89. }
  90. .wrapper{
  91. width: 100px;
  92. height: 100px;
  93. font-size: 10px;
  94. .inner{
  95. //@extend 继承某一个选择器的样式
  96. //编译的时候 会将相同的样式 转化成分组选择器
  97. //如果继承的选择器 有子选择器 会继承过来
  98. @extend .wrapper;
  99. padding: 20px;
  100. }
  101. }
  102. #main{
  103. @extend .wrapper;
  104. margin: 10px;
  105. }
  106. /*
  107. 绝对值: abs(-10px)
  108. 四舍五入:round(5.5)
  109. 向上取整:ceil(5.5)
  110. 向下取整:floor(5.5)
  111. 百分比:percentage(30px / 100px)
  112. 最小值: min(1,2,3)
  113. 最大值:max(1,2,3)
  114. */
  115. $width: 6;
  116. .content{
  117. width: percentage(30px / 100px);
  118. }
  119. //定义函数
  120. @function changeWidth($width){
  121. @return $width * 2
  122. }
  123. div{
  124. width: changeWidth(30px);
  125. }
  126. $list: 1px solid #000;
  127. $colorList: blue,red,yellow;
  128. p{
  129. border: $list;
  130. //nth($list,index)获取列表第几项
  131. background: nth($colorList,3);
  132. }
  133. //@if 指令 与js相同
  134. $length: 0;
  135. li{
  136. @if $length < 1{
  137. font-size: 12px;
  138. } @else if $length > 1 and $length < 4{
  139. font-size: 10px;
  140. } @else {
  141. font-size: 2px;
  142. }
  143. }
  144. //@for 类似于js中的for循环
  145. //through 包括
  146. @for $i from 1 through 3{
  147. .list-#{$i}{
  148. width: $i * 100px;
  149. }
  150. }
  151. //to 不包括
  152. @for $i from 1 to 3{
  153. .none-#{$i}{
  154. width: $i * 50px;
  155. }
  156. }