list.scss 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // @import 'max.scss';
  2. $bgcolor: #ff0000;
  3. $keyName: 'color';
  4. $whiteColor: #000000;
  5. /*
  6. sass使用 $ 符号来标识变量
  7. */
  8. //sass变量可以存储以下信息:字符串、数字
  9. //、颜色值、布尔值、列表null值
  10. /*! sass有作用域 */
  11. /*
  12. 多行注释 会在css文件里生成 但是不会再min.css文件里生成
  13. 单行注释 不会在css文件里生成
  14. 强制注释 会在css和min.css文件里生成
  15. */
  16. /*
  17. 插值语句
  18. #{变量} 属性名如果是变量可以使用这种
  19. 一般 不建议这么操作
  20. */
  21. div{
  22. width: 100px;
  23. height: 100px;
  24. background: $bgcolor;
  25. #{$keyName}: $bgcolor;
  26. }
  27. div2{
  28. width: 200px;
  29. height: 200px;
  30. background: $bgcolor;
  31. }
  32. //选择器的嵌套
  33. #list{
  34. width: 100px;
  35. height: 100px;
  36. li{
  37. font-size: 12px;
  38. p{
  39. // padding-top: 20px;
  40. // padding-left: 30px;
  41. //属性嵌套 : 和 { 中间一定要有一个空格
  42. padding: {
  43. top: 20px;
  44. left: 40px
  45. }
  46. }
  47. }
  48. //& 引用父选择器
  49. &-inner{
  50. color: $bgcolor;
  51. }
  52. }
  53. .link{
  54. color: $bgcolor;
  55. &:hover{
  56. color: #ccc;
  57. }
  58. }
  59. // .login-btn{
  60. // width: 100px;
  61. // height: 40px;
  62. // line-height: 40px;
  63. // text-align: center;
  64. // border-radius: 5px;
  65. // color: $whiteColor;
  66. // background: $bgcolor;
  67. // }
  68. // .submit-btn{
  69. // width: 50px;
  70. // height: 20px;
  71. // line-height: 20px;
  72. // text-align: center;
  73. // border-radius: 5px;
  74. // color: $whiteColor;
  75. // background: $bgcolor;
  76. // }
  77. //定义的一个混合宏
  78. //定义的时候可以带有参数 参数 也可以设置默认值
  79. @mixin logo-btn($width: 200px,$height: 100px,$lheight: 100px){
  80. width: $width;
  81. height: $height;
  82. line-height: $lheight;
  83. text-align: center;
  84. border-radius: 5px;
  85. color: $whiteColor;
  86. background: $bgcolor;
  87. }
  88. //通过@include 去调用设置的混合宏
  89. .login-btn{
  90. @include logo-btn(100px,40px,40px)
  91. }
  92. .submit-btn{
  93. @include logo-btn(50px,30px)
  94. }
  95. .del-btn{
  96. @include logo-btn()
  97. }
  98. .wrapper {
  99. width: 100px;
  100. height: 30px;
  101. font-size: 10px;
  102. .inner{
  103. //@extend 继承某一个选择器的样式
  104. //如果继承的选择器 有子选择器 会一并继承过来
  105. //编译的时候 会将相同的样式 转化成分组选择器
  106. @extend .wrapper;
  107. padding: 20px;
  108. p{
  109. color: $bgcolor;
  110. }
  111. }
  112. }
  113. #main{
  114. @extend .wrapper;
  115. margin: 10px
  116. }
  117. $width: 5.9px;
  118. .content{
  119. // width: ceil($width);
  120. // height: abs(-10px);
  121. width: percentage(30 / 100);
  122. }
  123. //@function 定义函数
  124. @function changeWidth($width){
  125. @return $width * 2
  126. }
  127. .last{
  128. width: changeWidth(4);
  129. }
  130. $list: 1px solid #000;
  131. div{
  132. width: changeWidth(40px);
  133. border-top: $list;
  134. }
  135. section{
  136. border-bottom: $list;
  137. }
  138. //列表要用逗号分割
  139. $colorList: red,blue,pink,green;
  140. p{
  141. //nth($list,index)通过索引获取列表当中的第index项
  142. color: nth($colorList,2)
  143. }
  144. $length: 2;
  145. li{
  146. //@if 指令 (与js中的if效果相同)
  147. //sass 中的逻辑判断 and or not
  148. @if $length > 0 and $length < 3{
  149. font-size: 12px;
  150. } @else if $length >= 3{
  151. font-size: 16px;
  152. }@else{
  153. font-size: 20px;
  154. }
  155. }
  156. //through 包含3
  157. @for $i from 1 through 3 {
  158. .list-#{$i}{
  159. width: $i * 100px;
  160. }
  161. }
  162. //to 不包含3
  163. @for $i from 1 to 3{
  164. .none-#{$i}{
  165. width: $i * 100px;
  166. }
  167. }
  168. //each in 循环列表
  169. @each $var in $colorList {
  170. .content-#{$var}{
  171. color: $var;
  172. }
  173. };
  174. $a: 3;
  175. @while $a > 0 {
  176. .none_#{$a} {
  177. width: 2px * $a;
  178. }
  179. $a: $a - 1;
  180. }