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声明

编译后的效果:

相关推荐
龙井>_<12 分钟前
uniapp“手搓”一个年月选择器模态框(兼容多端)
uni-app
web_Hsir23 分钟前
uniapp + vue2 + pfdjs + web-view 实现安卓、iOS App PDF预览
android·前端·uni-app
peachSoda741 分钟前
uniapp app使用命令行HBuilderX cli快捷打包iOS和Android
uni-app
她超甜i16 小时前
css省略号展示,兼容性强,js判断几行,不需要定位
javascript·css·vue.js
Mr Xu_17 小时前
深入分析Element UI Tree组件在本地与生产环境样式差异问题
css·ui·elementui
梦65017 小时前
CSS 元素垂直水平居中的 8 种方法
前端·css
前端 贾公子18 小时前
深入浅出 CSS 属性:pointer-events: none
前端·css
2501_9160074719 小时前
跨平台 App 安全,Flutter、RN、Unity、H5 混合应用加固
android·ios·小程序·https·uni-app·iphone·webview
咕咕咕_biubiubiu20 小时前
uniapp插件——原生插件开发和使用
uni-app
芋头莎莎20 小时前
UNIAPP连接MQTT记录要点
uni-app