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

编译后的效果:

相关推荐
TE-茶叶蛋3 小时前
Uniapp运行MuMu模拟器
uni-app
一人一程温一壶酒5 小时前
微信小程序uniapp开发附源码——图片加水印
微信小程序·uni-app·notepad++
一个假的前端男8 小时前
uniapp 3端轮播
前端·javascript·uni-app
Memory沙漏8 小时前
IOS如何免费申请开发者证书(uniapp开发)
ios·uni-app
一个打工仔的笔记10 小时前
使用css实现打开抽屉效果(css过渡动画)
css
fruge11 小时前
设计稿还原技巧:解决间距、阴影、字体适配的细节问题
前端·css
集成显卡11 小时前
AI取名大师 | uni-app + Wot UI 跟随设备自动切换明暗主题
人工智能·ui·uni-app·外观配色
zhangyao94033011 小时前
uni-app scroll-view特定情况下运用
前端·javascript·uni-app
kuilaurence12 小时前
CSS `border-image` 给文字加可拉伸边框
前端·css
LXA080913 小时前
在 UniApp 中为小程序实现视频播放记录功能
小程序·uni-app·音视频