本文主要是介绍uniapp使用scss仿tailwindcss进行常用样式封装便捷开发小程序或web,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
小程序版本
如果你开发的是小程序的话,或者包含小程序,就只能选这个版本,如果不包含小程序,更推荐使用H5版本
// 文字粗细
$font-weights: (thin: 100,extra-light: 200,light: 300,regular: 400,medium: 500,semi-bold: 600,bold: 700,extra-bold: 800,black: 900
);// 文字大小
@for $i from 8 through 25 {.font-#{$i} {font-size: #{$i}px;}
}@each $name, $weight in $font-weights {.font-#{$name} {font-weight: $weight;}
}$aligns: (left,center,right,justify
);// 文字位置
@each $align in $aligns {.text-#{$align} {text-align: $align;}
}// 颜色
$colors: (red: #ff0000,darkRed: #d90209,green: #00ff00,blue: #0000ff,black: #000000,white: #ffffff,gray: #808080,lightGray: #e6e6e6,orange: #ffA500,yellow: #ffff00,pink: #ff69b4,purple: #800080, brown: #a52a2a,cyan: #00ffff,lime: #00ff00,navy: #000080,olive: #808000,khaki: #f0e68c,salmon: #fa8072,coral: #ff7f50,gold: #ffd700,lavender: #e6e6fa,turquoise: #40e0d0,peach: #ffdab9,orchid: #da70d6,crimson: #dc143c,forestGreen: #228b22,sienna: #a0522d,sirocco: #736f6e,caputMortuum: #592720,zomp: #39a78e,paleTurquoise: #afeeee,lightSeaGreen: #20b2aa,dodgerBlue: #1e90ff,mediumSlateBlue: #7b68ee,blueViolet: #8a2be2,mediumOrchid: #ba55d3,thistle: #d8bfd8,deepPink: #ff1493,hotPink: #ff69b4,darkSlateGray: #2f4f4f,dimGray: #696969,slateBlue: #6a5acd,mediumBlue: #0000cd,cadetBlue: #5f9ea0,mediumAquamarine: #66cdaa,darkSeaGreen: #8fbc8f,lightGreen: #90ee90,springGreen: #00ff7f,chartreuse: #7fff00,mediumSpringGreen: #00fa9a,paleGoldenrod: #eee8aa,goldenrod: #daa520,sandyBrown: #f4a460,peru: #cd853f,rosyBrown: #bc8f8f,wheat: #f5deb3,darkOrange: #ff8c00,
);// 文字颜色
@each $name, $color in $colors {.text-#{$name} {color: $color;}
}// 布局
// Flex容器样式
.flex {display: flex;
}// 设置主轴方向
.flex-row {flex-direction: row;
}.flex-row-reverse {flex-direction: row-reverse;
}.flex-col {flex-direction: column;
}.flex-col-reverse {flex-direction: column-reverse;
}.flex-center {display: flex;justify-content: center;align-items: center;
}// 垂直居中
.vertical-center {display: flex;align-items: center; // 垂直居中
}// 水平居中
.horizontal-center {display: flex;justify-content: center; // 水平居中
}// 设置主轴对齐方式
.justify-start {justify-content: flex-start;
}.justify-end {justify-content: flex-end;
}.justify-center {justify-content: center;
}.justify-between {justify-content: space-between;
}.justify-around {justify-content: space-around;
}// 设置交叉轴对齐方式
.items-start {align-items: flex-start;
}.items-end {align-items: flex-end;
}.items-center {align-items: center;
}.items-baseline {align-items: baseline;
}.items-stretch {align-items: stretch;
}.items-spaceAround {align-items: space-around;
}.items-spaceBetween {align-items: space-between;
}// 设置子项在交叉轴上的对齐方式
.align-self-auto {align-self: auto;
}.align-self-flex-start {align-self: flex-start;
}.align-self-flex-end {align-self: flex-end;
}.align-self-center {align-self: center;
}.align-self-baseline {align-self: baseline;
}.align-self-stretch {align-self: stretch;
}// 设置子项的排序
.order-1 {order: 1;
}.order-2 {order: 2;
}.order-3 {order: 3;
}// 设置子项的伸缩比例
.flex-grow-1 {flex-grow: 1;
}.flex-grow-2 {flex-grow: 2;
}.flex-grow-3 {flex-grow: 3;
}// 设置子项的初始尺寸
.flex-shrink-1 {flex-shrink: 1;
}.flex-shrink-2 {flex-shrink: 2;
}.flex-shrink-3 {flex-shrink: 3;
}// 设置子项的伸缩基准
.flex-basis-auto {flex-basis: auto;
}.flex-basis-fill {flex-basis: fill;
}.flex-basis-content {flex-basis: content;
}.flex-basis-percent {flex-basis: 50%;
}// margin布局样式
.m-auto {margin: auto;
}.mt-auto {margin-top: auto;
}.mr-auto {margin-right: auto;
}.mb-auto {margin-bottom: auto;
}.ml-auto {margin-left: auto;
}.mx-auto {margin-left: auto;margin-right: auto;
}.my-auto {margin-top: auto;margin-bottom: auto;
}@for $i from -10 through 20 {.margin-#{$i} {margin: #{$i}px;}
}@for $i from -10 through 20 {.mt-#{$i} {margin-top: #{$i}px;}
}@for $i from -10 through 20 {.mr-#{$i} {margin-right: #{$i}px;}
}@for $i from -10 through 20 {.mb-#{$i} {margin-bottom: #{$i}px;}
}@for $i from -10 through 20 {.margin-left-#{$i} {margin-left: #{$i}px;}
}@for $i from -10 through 20 {.my-#{$i} {margin-top: #{$i}px;margin-bottom: #{$i}px;}
}@for $i from -10 through 20 {.mx-#{$i} {margin-right: #{$i}px;margin-left: #{$i}px;}
}// 背景颜色
@each $name, $color in $colors {.bg-#{$name} {background-color: $color;}
}// 宽度
@for $i from 1 through 75 {.w-#{$i * 10} {width: #{$i * 10}rpx;}
}// 宽度-%百分比
@for $i from 1 through 20 {.w-#{$i * 5}P {width: #{$i* 5%};}
}// 屏幕宽度
@for $i from 1 through 20 {.w-#{$i* 5%}vw {width: #{$i* 5%}vw;}
}// 高度
@for $i from 1 through 80 {.h-#{$i * 10} {height: #{$i * 10}rpx;}
}// 高度-%百分比
@for $i from 1 through 20 {.h-#{$i* 5%}P {height: #{$i* 5%};}
}// 屏幕高度
@for $i from 1 through 20 {.h-#{$i* 5%}vh {height: #{$i* 5%}vh;}
}// 内边距
@for $i from 1 through 20 {.p-#{$i} {padding: #{$i}px;}
}// 上内边距
@for $i from 1 through 20 {.pt-#{$i} {padding-top: #{$i}px;}
}// 右内边距
@for $i from 1 through 20 {.pr-#{$i} {padding-right: #{$i}px;}
}// 下内边距
@for $i from 1 through 20 {.pb-#{$i} {padding-bottom: #{$i}px;}
}// 左内边距
@for $i from 1 through 20 {.pl-#{$i} {padding-left: #{$i}px;}
}// 上下内边距
@for $i from 1 through 20 {.py-#{$i} {padding-top: #{$i}px;padding-bottom: #{$i}px;}
}// 左右内边距
@for $i from 1 through 20 {.px-#{$i} {padding-left: #{$i}px;padding-right: #{$i}px;}
}// 圆角
@for $i from 1 through 20 {.radius-#{$i} {border-radius: #{$i}px;}
}// 间隔
// 宽度
@for $i from 1 through 20 {.gap-#{$i} {gap: #{$i}rpx;}
}// 阴影
$shadows: (sm: (0 1px 2px 0 rgba(0, 0, 0, 0.05)),default: (0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)),md: (0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)),lg: (0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)),xl: (0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)),'2xl': (0 25px 50px -12px rgba(0, 0, 0, 0.25)),inner: (inset 0 2px 4px 0 rgba(0, 0, 0, 0.05)),none: (0 0 rgba(0, 0, 0, 0))
);@each $name, $value in $shadows {.shadow-#{$name} {box-shadow: $value;}
}// 边框
@for $i from 1 through 5 {@each $color-name, $color-value in $colors {.border-#{$i}-#{$color-name} {border: #{$i}px solid $color-value;}}
}@for $i from 1 through 5 {@each $color-name, $color-value in $colors {.border-top-#{$i}-#{$color-name} {border-top: #{$i}px solid $color-value;}.border-right-#{$i}-#{$color-name} {border-right: #{$i}px solid $color-value;}.border-bottom-#{$i}-#{$color-name} {border-bottom: #{$i}px solid $color-value;}.border-left-#{$i}-#{$color-name} {border-left: #{$i}px solid $color-value;}.border-x-#{$i}-#{$color-name} {border-left: #{$i}px solid $color-value;border-right: #{$i}px solid $color-value;}.border-y-#{$i}-#{$color-name} {border-top: #{$i}px solid $color-value;border-bottom: #{$i}px solid $color-value;}}
}// 父元素的1/2 使用方法:father-1_2
@for $i from 2 through 20 {.father-1_#{$i} {width: percentage(1 / $i); // 子元素宽度为父元素的分数}
}// 圆形,直径从5-100
@for $i from 1 through 20 {.circle-#{$i*10} {width: #{$i*10}px;height: #{$i*10}px;border-radius: 50%;}
}// 位于屏幕的最底部位置
.bottom-element {position: fixed;z-index: 1000; // 可以根据实际情况调整 z-indexbottom: 0;left: 0;right: 0;
}// 按钮的基本样式
.btn {transition: background-color 0.3s ease;
}// 按钮的点击后样式
.btn:active {background-color: #ff6600;
}
H5版本
// 文字粗细
$font-weights: (thin: 100,extra-light: 200,light: 300,regular: 400,medium: 500,semi-bold: 600,bold: 700,extra-bold: 800,black: 900
);// 文字大小
@for $i from 8 through 50 {.font-#{$i} {font-size: #{$i}px;}
}@each $name, $weight in $font-weights {.font-#{$name} {font-weight: $weight;}
}$aligns: (left,center,right,justify
);// 文字位置
@each $align in $aligns {.text-#{$align} {text-align: $align;}
}// 颜色
$colors: (red: #ff0000,darkRed: #d90209,green: #00ff00,blue: #0000ff,black: #000000,white: #ffffff,gray: #808080,lightGray: #e6e6e6,orange: #ffA500,yellow: #ffff00,pink: #ff69b4,purple: #800080, brown13: #a52a2a,cyan14: #00ffff,magenta15: #ff00ff,lime16: #00ff00,teal17: #008080,navy18: #000080,maroon19: #800000,olive20: #808000,beige21: #f5f5dc,ivory22: #fffff0,khaki23: #f0e68c,tan24: #d2b48c,salmon25: #fa8072,coral26: #ff7f50,tomato27: #ff6347,gold28: #ffd700,silver29: #c0c0c0,indigo30: #4b0082,lavender31: #e6e6fa,turquoise32: #40e0d0,violet33: #ee82ee,peach34: #ffdab9,orchid35: #da70d6,skyBlue36: #87ceeb,mintGreen37: #98ff98,crimson38: #dc143c,forestGreen39: #228b22,slateGray40: #708090,sienna41: #a0522d,sirocco42: #736f6e,caputMortuum43: #592720,terraCotta44: #e2725b,redOxide45: #7d4427,zomp46: #39a78e,yellowGreen47: #9acd32,paleGreen48: #98fb98,paleTurquoise49: #afeeee,robinEggBlue50: #00cccc,lightSeaGreen51: #20b2aa,deepSkyBlue52: #00bfff,dodgerBlue53: #1e90ff,steelBlue54: #4682b4,powderBlue55: #b0e0e6,cornflowerBlue56: #6495ed,mediumSlateBlue57: #7b68ee,darkSlateBlue58: #483d8b,blueViolet59: #8a2be2,mediumOrchid60: #ba55d3,darkOrchid61: #9932cc,thistle62: #d8bfd8,plum63: #dda0dd,paleVioletRed64: #db7093,deepPink65: #ff1493,hotPink66: #ff69b4,mediumPurple67: #9370db,darkMagenta68: #8b008b,darkViolet69: #9400d3,darkSlateGray70: #2f4f4f,dimGray71: #696969,slateBlue72: #6a5acd,mediumBlue73: #0000cd,midnightBlue74: #191970,cadetBlue75: #5f9ea0,aquamarine76: #7fffd4,mediumAquamarine77: #66cdaa,darkSeaGreen78: #8fbc8f,lightGreen79: #90ee90,springGreen80: #00ff7f,lawnGreen81: #7cfc00,chartreuse82: #7fff00,mediumSpringGreen83: #00fa9a,paleGoldenrod84: #eee8aa,goldenrod85: #daa520,sandyBrown86: #f4a460,peru87: #cd853f,rosyBrown88: #bc8f8f,wheat89: #f5deb3,tan90: #ffd39b,darkOrange91: #ff8c00,coral92: #ff7256,dodgerBlue93: #FF8C00,
);// 文字颜色
@each $name, $color in $colors {.text-#{$name} {color: $color;}
}// 布局
// Flex容器样式
.flex {display: flex;
}// 设置主轴方向
.flex-row {flex-direction: row;
}.flex-row-reverse {flex-direction: row-reverse;
}.flex-col {flex-direction: column;
}.flex-col-reverse {flex-direction: column-reverse;
}.flex-center {display: flex;justify-content: center;align-items: center;
}// 垂直居中
.vertical-center {display: flex;align-items: center; // 垂直居中
}// 水平居中
.horizontal-center {display: flex;justify-content: center; // 水平居中
}// 设置主轴对齐方式
.justify-start {justify-content: flex-start;
}.justify-end {justify-content: flex-end;
}.justify-center {justify-content: center;
}.justify-between {justify-content: space-between;
}.justify-around {justify-content: space-around;
}// 设置交叉轴对齐方式
.items-start {align-items: flex-start;
}.items-end {align-items: flex-end;
}.items-center {align-items: center;
}.items-baseline {align-items: baseline;
}.items-stretch {align-items: stretch;
}.items-spaceAround {align-items: space-around;
}.items-spaceBetween {align-items: space-between;
}// 设置子项在交叉轴上的对齐方式
.align-self-auto {align-self: auto;
}.align-self-flex-start {align-self: flex-start;
}.align-self-flex-end {align-self: flex-end;
}.align-self-center {align-self: center;
}.align-self-baseline {align-self: baseline;
}.align-self-stretch {align-self: stretch;
}// 设置子项的排序
.order-1 {order: 1;
}.order-2 {order: 2;
}.order-3 {order: 3;
}// 设置子项的伸缩比例
.flex-grow-1 {flex-grow: 1;
}.flex-grow-2 {flex-grow: 2;
}.flex-grow-3 {flex-grow: 3;
}// 设置子项的初始尺寸
.flex-shrink-1 {flex-shrink: 1;
}.flex-shrink-2 {flex-shrink: 2;
}.flex-shrink-3 {flex-shrink: 3;
}// 设置子项的伸缩基准
.flex-basis-auto {flex-basis: auto;
}.flex-basis-fill {flex-basis: fill;
}.flex-basis-content {flex-basis: content;
}.flex-basis-percent {flex-basis: 50%;
}// margin布局样式
.m-auto {margin: auto;
}.mt-auto {margin-top: auto;
}.mr-auto {margin-right: auto;
}.mb-auto {margin-bottom: auto;
}.ml-auto {margin-left: auto;
}.mx-auto {margin-left: auto;margin-right: auto;
}.my-auto {margin-top: auto;margin-bottom: auto;
}@for $i from -100 through 100 {.margin-#{$i} {margin: #{$i}px;}
}@for $i from -100 through 100 {.mt-#{$i} {margin-top: #{$i}px;}
}@for $i from -100 through 100 {.mr-#{$i} {margin-right: #{$i}px;}
}@for $i from -100 through 100 {.mb-#{$i} {margin-bottom: #{$i}px;}
}@for $i from -100 through 100 {.margin-left-#{$i} {margin-left: #{$i}px;}
}@for $i from -100 through 100 {.my-#{$i} {margin-top: #{$i}px;margin-bottom: #{$i}px;}
}@for $i from -100 through 100 {.mx-#{$i} {margin-right: #{$i}px;margin-left: #{$i}px;}
}// 背景颜色
@each $name, $color in $colors {.bg-#{$name} {background-color: $color;}
}// 宽度
@for $i from 10 through 750 {.w-#{$i} {width: #{$i}rpx;}
}// 宽度-%百分比
@for $i from 1 through 100 {.w-#{$i}P {width: #{$i* 1%};}
}// 屏幕宽度
@for $i from 1 through 100 {.w-#{$i}vw {width: #{$i}vw;}
}// 高度
@for $i from 10 through 800 {.h-#{$i} {height: #{$i}rpx;}
}// 高度-%百分比
@for $i from 1 through 100 {.h-#{$i}P {height: #{$i* 1%};}
}// 屏幕高度
@for $i from 1 through 100 {.h-#{$i}vh {height: #{$i}vh;}
}// 内边距
@for $i from 1 through 50 {.p-#{$i} {padding: #{$i}px;}
}// 上内边距
@for $i from 1 through 50 {.pt-#{$i} {padding-top: #{$i}px;}
}// 右内边距
@for $i from 1 through 50 {.pr-#{$i} {padding-right: #{$i}px;}
}// 下内边距
@for $i from 1 through 50 {.pb-#{$i} {padding-bottom: #{$i}px;}
}// 左内边距
@for $i from 1 through 50 {.pl-#{$i} {padding-left: #{$i}px;}
}// 上下内边距
@for $i from 1 through 50 {.py-#{$i} {padding-top: #{$i}px;padding-bottom: #{$i}px;}
}// 左右内边距
@for $i from 1 through 50 {.px-#{$i} {padding-left: #{$i}px;padding-right: #{$i}px;}
}// 圆角
@for $i from 1 through 50 {.radius-#{$i} {border-radius: #{$i}px;}
}// 间隔
// 宽度
@for $i from 1 through 50 {.gap-#{$i} {gap: #{$i}rpx;}
}// 阴影
$shadows: (sm: (0 1px 2px 0 rgba(0, 0, 0, 0.05)),default: (0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)),md: (0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)),lg: (0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)),xl: (0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)),'2xl': (0 25px 50px -12px rgba(0, 0, 0, 0.25)),inner: (inset 0 2px 4px 0 rgba(0, 0, 0, 0.05)),none: (0 0 rgba(0, 0, 0, 0))
);@each $name, $value in $shadows {.shadow-#{$name} {box-shadow: $value;}
}// 边框
@for $i from 1 through 50 {@each $color-name, $color-value in $colors {.border-#{$i}-#{$color-name} {border: #{$i}px solid $color-value;}}
}@for $i from 1 through 50 {@each $color-name, $color-value in $colors {.border-top-#{$i}-#{$color-name} {border-top: #{$i}px solid $color-value;}.border-right-#{$i}-#{$color-name} {border-right: #{$i}px solid $color-value;}.border-bottom-#{$i}-#{$color-name} {border-bottom: #{$i}px solid $color-value;}.border-left-#{$i}-#{$color-name} {border-left: #{$i}px solid $color-value;}.border-x-#{$i}-#{$color-name} {border-left: #{$i}px solid $color-value;border-right: #{$i}px solid $color-value;}.border-y-#{$i}-#{$color-name} {border-top: #{$i}px solid $color-value;border-bottom: #{$i}px solid $color-value;}}
}// 父元素的1/2 使用方法:father-1_2
@for $i from 2 through 10 {.father-1_#{$i} {width: percentage(1 / $i); // 子元素宽度为父元素的分数}
}// 圆形,直径从5-100
@for $i from 5 through 100 {.circle-#{$i} {width: #{$i}px;height: #{$i}px;border-radius: 50%;}
}// 位于屏幕的最底部位置
.bottom-element {position: fixed;z-index: 1000; // 可以根据实际情况调整 z-indexbottom: 0;left: 0;right: 0;
}// 按钮的基本样式
.btn {transition: background-color 0.3s ease;
}// 按钮的点击后样式
.btn:active {background-color: #ff6600;
}
这篇关于uniapp使用scss仿tailwindcss进行常用样式封装便捷开发小程序或web的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!