uniapp使用scss mixin抽离css常用的公共样式

1、编写通用scss样式文件

css 复制代码
// 通用 Flex Mixin
@mixin flex($direction: row, $justify: flex-start, $align: stretch, $wrap: nowrap) {
  display: flex;
  flex-direction: $direction;
  justify-content: $justify;
  align-items: $align;
  flex-wrap: $wrap;
}

// 水平居中
@mixin flex-center-horizontal {
  @include flex(row, center, center);
}

// 垂直居中
@mixin flex-center-vertical {
  @include flex(column, center, center);
}

// 文本省略号
@mixin ellipsis($lines: 1) {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: $lines; // 多行省略
  -webkit-box-orient: vertical;
}

// Clearfix (清除浮动)
@mixin clearfix {
  &::after {
    content: "";
    display: table;
    clear: both;
  }
}

// Box Shadow (阴影效果)
@mixin box-shadow($x: 0px, $y: 4px, $blur: 6px, $color: rgba(0, 0, 0, 0.1)) {
  box-shadow: $x $y $blur $color;
}

// Border Radius (圆角样式)
@mixin border-radius($radius: 4px) {
  border-radius: $radius;
}

// Transition (过渡动画)
@mixin transition($properties: all, $duration: 0.3s, $easing: ease) {
  transition: $properties $duration $easing;
}

// 绝对定位居中
@mixin absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

2、在uni.scss引入上述scss文件

3、在页面上使用,需加上lang=scss声明

编译后的效果:

相关推荐
Enti7c2 分钟前
用 HTML、CSS 和 jQuery 打造多页输入框验证功能
css·html·jquery
艾路菲尔39 分钟前
uniapp小程序登录失效后操作失灵问题
小程序·uni-app
艾路菲尔40 分钟前
uniapp微信小程序地图marker自定义气泡 customCallout偶尔显示不全解决办法
微信小程序·小程序·uni-app
Jasmin Tin Wei4 小时前
蓝桥杯 web 展开你的扇子(css3)
前端·css·css3
齐尹秦11 小时前
CSS Id 和 Class 选择器学习笔记
css·笔记·学习
小付同学呀12 小时前
前端快速入门学习4——CSS盒子模型、浮动、定位
前端·css·学习
一清三白15 小时前
《UniApp开发微信小程序:解决头部导航栏》
uni-app
前端小怪兽zmy16 小时前
css flex布局 让子元素在最右边技巧
前端·css
Kx…………16 小时前
Day2-2:前端项目uniapp壁纸实战
前端·学习·uni-app·html·实战·项目
CCChaya-软件技术教师18 小时前
21-盒子定位(CSS3)
前端·css·css3