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

编译后的效果:

相关推荐
浮桥9 分钟前
uniapp + h5实现悬浮活动按钮组件
前端·javascript·uni-app
Web_Lys10 分钟前
css设置滚动条样式不生效【antDesign UI Table滚动条样式无法自定义 解决方案】
前端·css
笨笨狗吞噬者1 小时前
【uniapp】小程序端解决分包的uni_modules打包后产物进入主包中的问题
前端·微信小程序·uni-app
结网的兔子2 小时前
前端开发(前言)——html,css,JavaScript和vue关系
javascript·css·html
清粥油条可乐炸鸡2 小时前
tailwind-variants基本使用
前端·css
清粥油条可乐炸鸡2 小时前
tailwindcss v4的基础使用
css
Never_Satisfied3 小时前
在HTML & CSS中,如何计算CSS特异性
前端·css·html
Lee川3 小时前
CSS自定义属性与JavaScript动态交互:现代Web开发的强大组合
css·面试
Lee川3 小时前
CSS Position属性深度解析:定位的艺术与科学
css·面试
光影少年3 小时前
CSS盒模型是什么?box-sizing有什么作用?
前端·css