Blog
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)

HiuZing

🍑
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)
  • 前端面试题

  • JavaScript

  • Vue2

  • port

  • CSS

    • flex

    • Scss

    • CSS常见问题

    • less

      • umi框架中使用less
        • 变量
          • 全局变量
          • 局部变量
        • 混合
        • 嵌套
        • 父选择器
  • Node.js

  • JavaScript优化

  • uniapp

  • Mini Program

  • TypeScript

  • 面向对象编程

  • UI组件

  • Plugin

  • Vue3

  • 性能优化

  • Axios

  • 状态管理

  • React

  • Mock

  • Icon

  • Template

  • 构建工具

  • 项目规范配置

  • Taro

  • SVG

  • React Native

  • 前端
  • CSS
  • less
HiuZing
2023-05-11
目录

umi框架中使用less

# 变量

# 全局变量

// global.less
import '~antd/es/style/themes/default.less'

.mylink{
    color:@primary-color;
}
1
2
3
4
5
6
<div className={mylink}>测试</div>
<div className="mylink">测试</div>
1
2

# 局部变量

// index.less
@width:100px;
@height:@width - 80px;

.header{
    width:@width;
    height:@height;
}
1
2
3
4
5
6
7
8
import styles from './index.less'
<div className={styles.header}>测试</div>
1
2

# 混合

// index.less
// topW 默认1px
.bordered(@topW:1px,@bottomW:2px){
	border-top:dotted @topW black;
	border-bottom:dotted @bottomW black;
}

#a1{
    color:#111;
    // 混入两个边框
    .bordered();
}

.a2{
    color:#111;
    // 混入并传入默认值
    .bordered(2px,4px);
    // 覆盖混合
    border-bottom:solid 5px black;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import styles from './index.less'
<div id={styles.a1}>测试</div>
<div className={styles.a2}>测试</div>
1
2
3

# 嵌套

// index.less
.nesting{
    color:blue;
    
    h3{
        color:orange;
    }
    
    p{
        color:aqua;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
import styles from './index.less'
<div className={styles.nesting}>
	<h3>测试</h3>
	<p>测试</p>
</div>
1
2
3
4
5

# 父选择器

运用模块化,会自动加上序列号,我们希望编译后,脱离模块化作用到全局(在局部编写样式作用到全局)

// index.less
.bars_right{
    font-weight:blod;
    // 希望下方选择器作用到全局
    :global{
        .ant_btn{
            border:0;
        }
        
        .title{
            background:#fafafa;
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import styles from './index.less';
<div className={styles.bars_right}>
    <button className={`ant-btn`}>按钮</button>
</div>
1
2
3
4
上次更新: 2024/08/14, 04:14:33
Animate.css
nvm介绍

← Animate.css nvm介绍→

最近更新
01
React Native 使用SVG
08-13
02
Docker基础命令
08-04
03
算数逻辑单元
07-30
更多文章>
Theme by Vdoing | Copyright © 2021-2024 WeiXiaojing | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式