目录
src/assets/css/...- base.scss - 将其他scss导入的地方 & 配置一些样式- reset.scss - html, body等初始化配置- variable.scss - 定义变量的地方(字体/背景颜色/字体颜色...)- mixin.scss - 混合 自定义函数动态设置样式
文件定义
base.scss
@import "./reset.scss";@import "./variable.scss";@import "./mixin.scss";html, body{width: 100%;height: 100%;overflow: hidden;// 解决IScroll拖拽卡顿问题touch-action: none;}body{//$font_medium in variable.scss@include font_size($font_medium);//@include font_size(50px);//font-size: 50px;font-family: Helvetica,sans-serif,STHeiTi;}img{vertical-align: bottom;}
reset.scss
/*YUI 3.18.1 (build f7e7bcb)Copyright 2014 Yahoo! Inc. All rights reserved.Licensed under the BSD License.http://yuilibrary.com/license/*/html{color:#000;background:#FFF}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}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}ol,ul{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:text-top}sub{vertical-align:text-bottom}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;*font-size:100%}legend{color:#000}a{text-decoration: none}#yui3-css-stamp.cssreset{display:none}
variable.scss
//字体定义规范$font_samll:12Px;$font_medium_s:13Px;$font_medium:15Px;$font_large:17Px;// 背景颜色规范(主要)$background-color-theme: #d43c33;//背景主题颜色默认(网易红)$background-color-theme1: rgba(34,213,156,1);//背景主题颜色1(QQ绿)$background-color-theme2: #333;//背景主题颜色2(夜间模式)// 背景颜色规范(次要)$background-color-sub-theme: #f5f5f5;//背景主题颜色默认(网易红)$background-color-sub-theme1: #f5f5f5;//背景主题颜色1(QQ绿)$background-color-sub-theme2: #444;//背景主题颜色2(夜间模式)// 字体颜色规范(默认)$font-color-theme : #666;//字体主题颜色默认(网易)$font-color-theme1 : #666;//字体主题颜色1(QQ)$font-color-theme2 : #ddd;//字体主题颜色2(夜间模式)// 字体颜色规范(激活)$font-active-color-theme : #d43c33;//字体主题颜色默认(网易红)$font-active-color-theme1 : rgba(34,213,156,1);//字体主题颜色1(QQ绿)$font-active-color-theme2 : #ffcc33;//字体主题颜色2(夜间模式)// 边框颜色$border-color-theme : #d43c33;//边框主题颜色默认(网易)$border-color-theme1 : rgba(34,213,156,1);//边框主题颜色1(QQ)$border-color-theme2 : #ffcc33;//边框主题颜色2(夜间模式)
mixin.scss
@import "./variable.scss";/*根据dpr计算font-size*/@mixin font_dpr($font-size){font-size: $font-size;// 根据像素比缩放字体大小 达到视口变化而字体不变[data-dpr="2"] & { font-size: $font-size * 2;}[data-dpr="3"] & { font-size: $font-size * 3;}}/*通过该函数设置字体大小,后期方便统一管理;*/@mixin font_size($size){@include font_dpr($size);}// 不换行@mixin no-wrap(){text-overflow: ellipsis;overflow: hidden;white-space: nowrap;}// 限制行数@mixin clamp($row){overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:$row;}//根据属性选择器设置背景颜色@mixin bg_color(){background: $background-color-theme;[data-theme=theme1] & {background: $background-color-theme1;}[data-theme=theme2] & {background: $background-color-theme2;}}//不同主题和不同像素比下显示不同图片//不同设置background:url() 这样background-size不起作用@mixin bg_img($url) {[data-theme=theme] & {background-image: url($url + '_163.png');}[data-theme=theme1] & {background-image: url($url + '_qq.png');}[data-theme=theme2] & {background-image: url($url + '_it666.png');}background-size: cover;background-repeat: no-repeat;[data-theme=theme][data-dpr='2'] & {background-image: url($url + '_163@2x.png');}[data-theme=theme][data-dpr='3'] & {background-image: url($url + '_163@3x.png');}[data-theme=theme1][data-dpr='2'] & {background-image: url($url + '_qq@2x.png');}[data-theme=theme1][data-dpr='3'] & {background-image: url($url + '_qq@3x.png');}[data-theme=theme2][data-dpr='2'] & {background-image: url($url + '_it666@2x.png');}[data-theme=theme2][data-dpr='3'] & {background-image: url($url + '_it666@3x.png');}}//改变tabbar背景颜色@mixin bg_sub_color(){background: $background-color-sub-theme;[data-theme=theme1] & {background: $background-color-sub-theme1;}[data-theme=theme2] & {background: $background-color-sub-theme2;}}//改变tabbar字体颜色@mixin font_color(){color: $font-color-theme;[data-theme=theme1] & {color: $font-color-theme1;}[data-theme=theme2] & {color: $font-color-theme2;}}//改变tabbar字体激活线颜色@mixin font_active_color(){color: $font-active-color-theme;[data-theme=theme1] & {color: $font-active-color-theme1;}[data-theme=theme2] & {color: $font-active-color-theme2;}}//tabbar下划线@mixin border_color(){border-color: $border-color-theme;[data-theme=theme1] & {border-color: $border-color-theme1;}[data-theme=theme2] & {border-color: $border-color-theme2;}}
组件使用
<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>
