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

编译后的效果:

相关推荐
行走的陀螺仪19 小时前
重绘和重排怎么触发?怎么优化?
前端·css·性能优化·css3·浏览器原理
wangdaoyin201020 小时前
UniApp中使用LivePlayer进行视频或在流媒体播放
uni-app·liveplayer·h5播放视频
2501_9151063220 小时前
App HTTPS 抓包实战解析,从代理调试到真实网络流量观察的完整抓包思路
网络协议·http·ios·小程序·https·uni-app·iphone
syt_101320 小时前
grid布局-子项放置3
前端·javascript·css
TG:@yunlaoda360 云老大21 小时前
如何了解腾讯云国际站代理商CSS的服务流程是怎样的?
css·云计算·腾讯云
游戏开发爱好者821 小时前
苹果App Store应用程序上架方式全面指南
android·小程序·https·uni-app·iphone·webview
2501_9160088921 小时前
深入理解 iPhone 文件管理,从沙盒结构到开发调试的多工具协同实践
android·ios·小程序·https·uni-app·iphone·webview
Youyzq1 天前
css样式用flex 布局的时候元素尺寸展示不对
前端·javascript·css
一室易安1 天前
解决使用 UniApp 搭配 Vue3 小程序开始 使用uview-plus 的返回顶部up-back-top中onPageScroll 不触发的问题
小程序·uni-app
小明记账簿1 天前
利用 Less 循环高效生成多组 CSS 间距工具类
前端·css·less