Skip to content

Commit

Permalink
feat(sass): add interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzhuan committed Nov 12, 2024
1 parent c0cd529 commit e7b9408
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions _posts/2024-11-12-sass-lang.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,36 @@ aside[role=complementary] {

上面源代码中的 [`"sass:math"`](https://sass-lang.com/documentation/modules/math/) 是 Sass 内置的数学模块。

## 插值 {#interpolation}

插值几乎可以用在 Sass 样式表的任意地方,只要把变量使用 `#{}` 包裹即可。

源代码:

```scss
@mixin corner-icon($name, $top-or-bottom, $left-or-right) {
.icon-#{$name} {
background-image: url("/icons/#{$name}.svg");
position: absolute;
#{$top-or-bottom}: 0;
#{$left-or-right}: 0;
}
}

@include corner-icon("mail", top, left);
```

编译结果:

```css
.icon-mail {
background-image: url("/icons/mail.svg");
position: absolute;
top: 0;
left: 0;
}
```

## 内置模块 {#built-in-modules}

Sass 的内置模块包括:
Expand Down

0 comments on commit e7b9408

Please sign in to comment.