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

编译后的效果:

相关推荐
陈不知代码5 小时前
uniapp创建vue3+ts+pinia+sass项目
前端·uni-app·sass
源码_V_saaskw5 小时前
JAVA图文短视频交友+自营商城系统源码支持小程序+Android+IOS+H5
java·微信小程序·小程序·uni-app·音视频·交友
涔溪8 小时前
响应式前端设计:CSS 自适应布局与字体大小的最佳实践
前端·css
996幸存者10 小时前
uni-app区域选择、支持静态、动态数据
微信小程序·uni-app
ᥬ 小月亮11 小时前
Uniapp编写微信小程序,绘制动态圆环进度条
微信小程序·小程序·uni-app
代码的余温12 小时前
CSS3文本阴影特效全攻略
前端·css·css3
每天开心12 小时前
告别样式冲突:CSS 模块化实战
前端·css·代码规范
耶啵奶膘15 小时前
uniapp+vue3——通知栏标题纵向滚动切换
uni-app
3Katrina16 小时前
我仿造了一个掘金App的首页...
前端·css
The_era_achievs_hero18 小时前
UniappDay03
vue.js·微信小程序·uni-app