仲灏小栈 仲灏小栈
首页
大前端
后端&运维
其他技术
生活
关于我
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

仲灏

诚意, 正心, 格物, 致知
首页
大前端
后端&运维
其他技术
生活
关于我
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 《前端项目基础建设》
  • HTML&CSS

    • Scss语言学习实用心得
      • 数据类型
        • 字符串
        • 数组列表
        • 访问
        • 查看
        • 添加
        • map 对象
        • 查询
        • 循环
        • 添加
        • 合并
    • H5 标签使用场景
    • css常用命名单词
    • 项目基础建设 css与处理器scss
    • 项目基础建设 CSS公共样式
    • iframe
    • css 变量使用
    • css常见但不常用的属性
    • 躺着旋转动画
    • 边框渐变(圆形)
    • float 布局
    • 在 Javascript 和 Sass(或 CSS!)之间共享变量的方法
    • 看不见的html标签
    • 手写css预处理器
    • grid vs flex布局
  • JavaScript&TypeScript

  • Node

  • 构建

  • Vue

  • React

  • 小程序

  • 跨端

  • Electron

  • WebGL&GIS

  • 浏览器

  • 面经

  • 其他

  • 大前端
  • HTML&CSS
仲灏
2020-12-11
目录

Scss语言学习实用心得

# 数据类型

# 字符串

@use "sass:string";
$prefix: ms;

.test {
    font-size: -#{$prefix}-flex; // -ms-flex;
    font-size: \1F46D;  // 👭;
    font-size: \21; // \!;
    font-size: string.length(\7Fx); // 5;
    font-size: string.slice("Roboto Mono", -4); // "Mono";
    font-size: string.index("Helvetica Neue", "Helvetica"); // 1;
}

1
2
3
4
5
6
7
8
9
10
11
12

# 数组列表

# 访问

@use "sass:list";

.test {
    font-size: list.nth(10px 12px 16px, 2); // 12px
}
1
2
3
4
5

# 查看

不需要添加@use "sass:list";

$sizes: 40px, 50px, 80px;

@each $size in $sizes {
  .icon-#{$size} {
    font-size: $size;
    height: $size;
    width: $size;
  }
}

// 编译后
.icon-40px {
  font-size: 40px;
  height: 40px;
  width: 40px;
}

.icon-50px {
  font-size: 50px;
  height: 50px;
  width: 50px;
}

.icon-80px {
  font-size: 80px;
  height: 80px;
  width: 80px;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# 添加

@use "sass:list";

.test {
    // font-size: list.nth(10px 12px 16px, 2); // 12px
    // font-size: list.nth([line1, line2, line3], -1); // line3
    
    font-size: list.index(1px solid red, 1px); // 1
    font-size:  list.index(1px solid red, solid); // 2
    font-size:  list.index(1px solid red, dashed); // null 不会显示这个样式
}

1
2
3
4
5
6
7
8
9
10
11

# map 对象

# 查询

@use "sass:map";
$font-weights: ("regular": 400, "medium": 500, "bold": 700);

.test {
    font-size: map.get($font-weights, "medium"); // 500;
    font-size: map.get($font-weights, "extra-bold"); // null
}
1
2
3
4
5
6
7

# 循环

$icons: ("eye": "\f112", "start": "\f12e", "stop": "\f12f");

@each $name, $glyph in $icons {
  .icon-#{$name}:before {
    display: inline-block;
    font-family: "Icon Font";
    content: $glyph;
  }
}

// 编译
.icon-eye:before {
  display: inline-block;
  font-family: "Icon Font";
  content: "";
}

.icon-start:before {
  display: inline-block;
  font-family: "Icon Font";
  content: "";
}

.icon-stop:before {
  display: inline-block;
  font-family: "Icon Font";
  content: "";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# 添加

@use "sass:map";

$font-weights: ("regular": 400, "medium": 500, "bold": 700);

map.set($font-weights, "extra-bold", 900); // ("regular": 400, "medium": 500, "bold": 700, "extra-bold": 900)

map.set($font-weights, "bold", 900);// ("regular": 400, "medium": 500, "bold": 900)
1
2
3
4
5
6
7

# 合并

@use "sass:map";

$light-weights: ("lightest": 100, "light": 300);
$heavy-weights: ("medium": 500, "bold": 700);

map.merge($light-weights, $heavy-weights); // ("lightest": 100, "light": 300, "medium": 500, "bold": 700)


$weights: ("light": 300, "medium": 500);
map.merge($weights, ("medium": 700)); // ("light": 300, "medium": 700)
1
2
3
4
5
6
7
8
9
10
#HTML&CSS
上次更新: 2022/05/04, 15:35:13
《前端项目基础建设》
H5 标签使用场景

← 《前端项目基础建设》 H5 标签使用场景→

最近更新
01
vim日常使用记录
04-02
02
滑动窗口最大值
04-02
03
有效的字母异位词
04-02
更多文章>
Theme by Vdoing | Copyright © 2021-2025 izhaong | github | 蜀ICP备2021031194号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式