目录

  1. src/assets/css/...
  2. - base.scss - 将其他scss导入的地方 & 配置一些样式
  3. - reset.scss - html, body等初始化配置
  4. - variable.scss - 定义变量的地方(字体/背景颜色/字体颜色...)
  5. - mixin.scss - 混合 自定义函数动态设置样式

文件定义

base.scss

  1. @import "./reset.scss";
  2. @import "./variable.scss";
  3. @import "./mixin.scss";
  4. html, body{
  5. width: 100%;
  6. height: 100%;
  7. overflow: hidden;
  8. // 解决IScroll拖拽卡顿问题
  9. touch-action: none;
  10. }
  11. body{
  12. //$font_medium in variable.scss
  13. @include font_size($font_medium);
  14. //@include font_size(50px);
  15. //font-size: 50px;
  16. font-family: Helvetica,sans-serif,STHeiTi;
  17. }
  18. img{
  19. vertical-align: bottom;
  20. }

reset.scss

  1. /*
  2. YUI 3.18.1 (build f7e7bcb)
  3. Copyright 2014 Yahoo! Inc. All rights reserved.
  4. Licensed under the BSD License.
  5. http://yuilibrary.com/license/
  6. */
  7. html{color:#000;background:#FFF}
  8. body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0}
  9. table{border-collapse:collapse;border-spacing:0}
  10. fieldset,img{border:0}
  11. address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}
  12. ol,ul{list-style:none}
  13. caption,th{text-align:left}
  14. h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}
  15. q:before,q:after{content:''}
  16. abbr,acronym{border:0;font-variant:normal}
  17. sup{vertical-align:text-top}
  18. sub{vertical-align:text-bottom}
  19. input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;*font-size:100%}
  20. legend{color:#000}
  21. a{text-decoration: none}
  22. #yui3-css-stamp.cssreset{display:none}

variable.scss

  1. //字体定义规范
  2. $font_samll:12Px;
  3. $font_medium_s:13Px;
  4. $font_medium:15Px;
  5. $font_large:17Px;
  6. // 背景颜色规范(主要)
  7. $background-color-theme: #d43c33;//背景主题颜色默认(网易红)
  8. $background-color-theme1: rgba(34,213,156,1);//背景主题颜色1(QQ绿)
  9. $background-color-theme2: #333;//背景主题颜色2(夜间模式)
  10. // 背景颜色规范(次要)
  11. $background-color-sub-theme: #f5f5f5;//背景主题颜色默认(网易红)
  12. $background-color-sub-theme1: #f5f5f5;//背景主题颜色1(QQ绿)
  13. $background-color-sub-theme2: #444;//背景主题颜色2(夜间模式)
  14. // 字体颜色规范(默认)
  15. $font-color-theme : #666;//字体主题颜色默认(网易)
  16. $font-color-theme1 : #666;//字体主题颜色1(QQ)
  17. $font-color-theme2 : #ddd;//字体主题颜色2(夜间模式)
  18. // 字体颜色规范(激活)
  19. $font-active-color-theme : #d43c33;//字体主题颜色默认(网易红)
  20. $font-active-color-theme1 : rgba(34,213,156,1);//字体主题颜色1(QQ绿)
  21. $font-active-color-theme2 : #ffcc33;//字体主题颜色2(夜间模式)
  22. // 边框颜色
  23. $border-color-theme : #d43c33;//边框主题颜色默认(网易)
  24. $border-color-theme1 : rgba(34,213,156,1);//边框主题颜色1(QQ)
  25. $border-color-theme2 : #ffcc33;//边框主题颜色2(夜间模式)

mixin.scss

  1. @import "./variable.scss";
  2. /*根据dpr计算font-size*/
  3. @mixin font_dpr($font-size){
  4. font-size: $font-size;
  5. // 根据像素比缩放字体大小 达到视口变化而字体不变
  6. [data-dpr="2"] & { font-size: $font-size * 2;}
  7. [data-dpr="3"] & { font-size: $font-size * 3;}
  8. }
  9. /*通过该函数设置字体大小,后期方便统一管理;*/
  10. @mixin font_size($size){
  11. @include font_dpr($size);
  12. }
  13. // 不换行
  14. @mixin no-wrap(){
  15. text-overflow: ellipsis;
  16. overflow: hidden;
  17. white-space: nowrap;
  18. }
  19. // 限制行数
  20. @mixin clamp($row){
  21. overflow:hidden;
  22. text-overflow:ellipsis;
  23. display:-webkit-box;
  24. -webkit-box-orient:vertical;
  25. -webkit-line-clamp:$row;
  26. }
  27. //根据属性选择器设置背景颜色
  28. @mixin bg_color(){
  29. background: $background-color-theme;
  30. [data-theme=theme1] & {
  31. background: $background-color-theme1;
  32. }
  33. [data-theme=theme2] & {
  34. background: $background-color-theme2;
  35. }
  36. }
  37. //不同主题和不同像素比下显示不同图片
  38. //不同设置background:url() 这样background-size不起作用
  39. @mixin bg_img($url) {
  40. [data-theme=theme] & {
  41. background-image: url($url + '_163.png');
  42. }
  43. [data-theme=theme1] & {
  44. background-image: url($url + '_qq.png');
  45. }
  46. [data-theme=theme2] & {
  47. background-image: url($url + '_it666.png');
  48. }
  49. background-size: cover;
  50. background-repeat: no-repeat;
  51. [data-theme=theme][data-dpr='2'] & {
  52. background-image: url($url + '_163@2x.png');
  53. }
  54. [data-theme=theme][data-dpr='3'] & {
  55. background-image: url($url + '_163@3x.png');
  56. }
  57. [data-theme=theme1][data-dpr='2'] & {
  58. background-image: url($url + '_qq@2x.png');
  59. }
  60. [data-theme=theme1][data-dpr='3'] & {
  61. background-image: url($url + '_qq@3x.png');
  62. }
  63. [data-theme=theme2][data-dpr='2'] & {
  64. background-image: url($url + '_it666@2x.png');
  65. }
  66. [data-theme=theme2][data-dpr='3'] & {
  67. background-image: url($url + '_it666@3x.png');
  68. }
  69. }
  70. //改变tabbar背景颜色
  71. @mixin bg_sub_color(){
  72. background: $background-color-sub-theme;
  73. [data-theme=theme1] & {
  74. background: $background-color-sub-theme1;
  75. }
  76. [data-theme=theme2] & {
  77. background: $background-color-sub-theme2;
  78. }
  79. }
  80. //改变tabbar字体颜色
  81. @mixin font_color(){
  82. color: $font-color-theme;
  83. [data-theme=theme1] & {
  84. color: $font-color-theme1;
  85. }
  86. [data-theme=theme2] & {
  87. color: $font-color-theme2;
  88. }
  89. }
  90. //改变tabbar字体激活线颜色
  91. @mixin font_active_color(){
  92. color: $font-active-color-theme;
  93. [data-theme=theme1] & {
  94. color: $font-active-color-theme1;
  95. }
  96. [data-theme=theme2] & {
  97. color: $font-active-color-theme2;
  98. }
  99. }
  100. //tabbar下划线
  101. @mixin border_color(){
  102. border-color: $border-color-theme;
  103. [data-theme=theme1] & {
  104. border-color: $border-color-theme1;
  105. }
  106. [data-theme=theme2] & {
  107. border-color: $border-color-theme2;
  108. }
  109. }

组件使用

<style lang="scss" scoped>
@import "../assets/css/mixin";
@import "../assets/css/variable";

  .song-list{
    width: 100%;
    @include bg_sub_color();
    .item{
      height: 200px;
      width: 100%;
      border-bottom:1px solid #fff;
      padding: 0 20px;
      display: flex;
      align-items: center;
      img{
        width: 150px;
        height: 150px;
        border-radius: 20px;
        margin-right: 20px;
      }
      h3{
        @include font_color();
        @include font_size($font_large);
      }
      p{
        @include font_color();
        @include font_size($font_samll);
        margin-top: 20px;
        opacity: 0.6;
      }
    }
  }
</style>