CSS - 妙用Sass

官方文档:https://www.sass.hk/docs/

1.例1:

bash 复制代码
@each $theme in $themeList {
  $themeKey: map-get($theme, 'key');
  @media screen and (weex-theme: $themeKey) {
    .btnText {
      max-width: 150px;
      @include font(map-get($theme, 'medFont'),map-get($theme, 'subFontSize'),400);
      @include ellipsis(2);
      color: map-get($theme, 'whiteColor');
      text-align: center;
    }
  }
}
/**
@each $theme in $themeList:
这是一个循环语句,遍历$themeList中的每个主题。
$themeList通常是一个包含多个主题的列表,每个主题是一个映射(map)。

$themeKey: map-get($theme, 'key'):
从当前主题映射中获取键值为'key'的值,并将其赋值给$themeKey。
map-get是Sass中的一个函数,用于从映射中获取值。

@media screen and (weex-theme: $themeKey):
这是一个媒体查询,用于根据不同的主题键值应用不同的样式。
weex-theme是一个自定义的媒体查询特性,用于在Weex中切换主
*/
  • 【逐步分析】
    xx组件:
bash 复制代码
<style lang="scss" scoped>
@import './config.scss';

@each $theme in $themeList {
  $themeKey: map-get($theme, 'key');
  @media screen and (weex-theme: $themeKey) {
    .btnText {
      max-width: 150px;
      @include font(map-get($theme, 'medFont'),map-get($theme, 'subFontSize'),400);
      @include ellipsis(2);
      color: map-get($theme, 'whiteColor');
      text-align: center;
    }
  }
}
</style>

config.scss:

bash 复制代码
@charset "UTF-8";

@import '../../../css/uiStandard/scss/default.scss';
$themeList: $mideaO100, $default;

default.scss:

bash 复制代码
@charset "UTF-8";
$default:(
  key: 'default',
  bigBtnHeight: 92px,
);
相关推荐
Uyker14 分钟前
微信小程序动态效果实战指南:从悬浮云朵到丝滑列表加载
前端·微信小程序·小程序
小小小小宇38 分钟前
前端按需引入总结
前端
小小小小宇1 小时前
React 的 DOM diff笔记
前端
小小小小宇1 小时前
react和vue DOM diff 简单对比
前端
我在北京coding1 小时前
6套bootstrap后台管理界面源码
前端·bootstrap·html
Carlos_sam1 小时前
Opnelayers:封装Popup
前端·javascript
前端小白从0开始2 小时前
Vue3项目实现WPS文件预览和内容回填功能
前端·javascript·vue.js·html5·wps·文档回填·文档在线预览
難釋懷3 小时前
Vue解决开发环境 Ajax 跨域问题
前端·vue.js·ajax
特立独行的猫a3 小时前
Nuxt.js 中的路由配置详解
开发语言·前端·javascript·路由·nuxt·nuxtjs