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

编译后的效果:

相关推荐
parade岁月20 小时前
Tailwind CSS v4 — 当框架猜不透你的心思
前端·css
前端Hardy1 天前
HTML&CSS&JS:基于定位的实时天气卡片
javascript·css·html
HashTang1 天前
【AI 编程实战】第 12 篇:从 0 到 1 的回顾 - 项目总结与 AI 协作心得
前端·uni-app·ai编程
JunjunZ1 天前
uniapp 文件预览:从文件流到多格式预览的完整实现
前端·uni-app
程序员阿耶1 天前
5 个让 CSS 起飞的新特性,设计师看了直呼内行
css
前端Hardy1 天前
HTML&CSS:纯CSS实现随机转盘抽奖机——无JS,全靠现代CSS黑科技!
css·html
漂流瓶jz2 天前
BEM、OOCSS、SMACSS、ITCSS、AMCSS、SUITCSS:CSS命名规范简介
前端·css·代码规范
郑州光合科技余经理2 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
TT_Close2 天前
“啪啪啪”三下键盘,极速拉起你的 uni-app 项目!
vue.js·uni-app·前端工程化
前端Hardy2 天前
HTML&CSS:高颜值产品卡片页面,支持主题切换
css·html