主题
Css
BEM
- B: 块
u-form - E: 元素
u-form__input - M: 修饰
u-form--success
Sass
mixin
scss
// flex
@mixin flex($alignItem: center, $justifyContent: flex-start, $direction: row) {
display: flex;
align-items: $alignItem;
justify-content: $justifyContent;
flex-direction: $direction;
}
// 文本省略
@mixin ellipsis($num) {
@if $num >1 {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: $num;
}
@else if $num ==1 {
overflow: hidden;
white-space: nowrap !important;
text-overflow: ellipsis;
}
}
// icon 样式
@mixin icon-style($size: 20px, $margin: unset) {
width: $size !important;
height: $size !important;
margin: $margin !important;
}
// 绝对定位居中
@mixin absolute-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
// 禁止文字换行
@mixin text-nowrap {
text-wrap: nowrap;
white-space: nowrap;
word-break: keep-all;
}
@mixin scroll-bar {
// 滚动条凹槽的颜色,还可以设置边框属性
&::-webkit-scrollbar-track-piece {
background-color: #f8f8f8;
}
// 滚动条的宽度
&::-webkit-scrollbar {
width: 9px;
height: 9px;
}
// 滚动条的设置
&::-webkit-scrollbar-thumb {
background-color: #dddddd;
background-clip: padding-box;
min-height: 28px;
}
&::-webkit-scrollbar-thumb:hover {
background-color: #bbb;
}
}reset
scss
body,
ul,
ol,
li,
p,
h1,
h2,
h3,
h4,
h5,
h6,
form,
fieldset,
table,
td,
img,
pre,
div {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul,
ol {
list-style-type: none;
}
select,
input,
img,
select {
vertical-align: middle;
}
/*p span 自动换行*/
p,
span {
word-break: break-all;
}
body {
font-size: 14px !important;
height: 100vh;
font-family: 'PingFangSC-Regular', 'Microsoft YaHei', 'Helvetica', 'sans-serif';
overflow: auto;
}
a {
text-decoration: none;
}Less
mixin
less
.flex(@justify: center; @align: center; @direction: row; @wrap: nowrap) {
display: flex;
flex-direction: @direction;
justify-content: @justify;
align-items: @align;
flex-wrap: @wrap;
}
.ellipsis(@lines: 1) {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: @lines;
-webkit-box-orient: vertical;
}常用片段
文字左右对齐
css
.test {
width: 70px;
text-align-last: justify;
}文字无法选中
css
.test {
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
-ms-user-select: none;
}清除图片间距
css
.img {
display: block;
}点击穿透与禁用样式
css
.test {
pointer-events: none;
}模糊滤镜
css
.test {
backdrop-filter: blur(3px);
}使用本地字体
字体过大使用在线字体工具压缩一下 网址
css
@font-face {
font-family: 'MyFont';
src:
url('@/assets/fonts/MyFont-Regular.woff2') format('woff2'),
url('@/assets/fonts/MyFont-Regular.woff') format('woff');
font-weight: 400;
font-style: normal;
font-display: swap; /* 优化加载体验 */
}
/*使用*/
.title {
font-family: 'MyFont', serif;
}移动端img标签禁用拖动/缩放/滚动/选中
背景:微信浏览器img标签长按保存图片,会造成img进行拖动、放大,操作体验不好
css
img {
width: 100%;
height: 100%;
user-select: none; /* 禁止选中 */
-webkit-user-drag: none; /* 禁止拖动图片 */
touch-action: manipulation; /* 阻止双指缩放/滚动 */
display: block;
}禁止文字换行
css
text-wrap: nowrap;
white-space: nowrap;
word-break: keep-all;背景图片
css
.banner {
background-image: url('@/assets/images/survey/bg.png');
background-size: 100% auto; /* 宽度100%,高度自适应 */
background-repeat: no-repeat;
background-position: top center; /* 顶部居中 */
}渐变背景
css
background: linear-gradient(180deg, #98c1ef 0%, #bfd3ff 23%, rgba(169, 187, 241, 0.2) 100%);内边框
css
box-shadow: inset 0 0 0 1px #7472fa;