Skip to content

Commit b200008

Browse files
author
dddssw
committed
sass
1 parent 7b67cf3 commit b200008

File tree

2 files changed

+27
-53
lines changed

2 files changed

+27
-53
lines changed

configure/component.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,3 +459,24 @@ color: getCssVar('color', 'primary')
459459
}
460460
```
461461
:::
462+
463+
464+
### 遵守BEM命名规则生成组件类名
465+
1. 生成块的类名
466+
::: code-group
467+
```scss [mixin/mixins.scss]
468+
@mixin b($block) {
469+
$B: $namespace + $common-separator + $block !global;
470+
471+
.#{$B} {
472+
@content;
473+
}
474+
}
475+
```
476+
``` scss [use]
477+
@include b(alert) {
478+
@include set-component-css-var('alert', $alert);
479+
//...样式
480+
}
481+
```
482+
:::

packages/sass.md

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -73,64 +73,17 @@ body {
7373
}
7474
```
7575
## mixin
76-
重用一组样式,当然不仅可以包含属性,也可以包含css规则,包含选择器和选择器中的属性
77-
```css
78-
@mixin no-bullets {
79-
list-style: none;
80-
li {
81-
list-style-image: none;
82-
list-style-type: none;
83-
margin-left: 0px;
84-
}
85-
}
86-
87-
ul.plain {
88-
color: #444;
89-
@include no-bullets;
90-
}
91-
92-
-->
76+
使用 `@mixin` 定义, 使用方式 `@mixin <name> { ... }` or `@mixin name(<arguments...>) { ... }`
9377

94-
ul.plain {
95-
color: #444;
96-
list-style: none;
97-
}
98-
ul.plain li {
99-
list-style-image: none;
100-
list-style-type: none;
101-
margin-left: 0px;
102-
}
103-
```
104-
`@include` 指令会将引入mixin的那行代码替换成mixin里边的内容
78+
使用上 `@include <name>` or `@include <name>(<arguments...>)`
10579

106-
### 给mixin进行传参
107-
```css
108-
@mixin link-colors($normal, $hover, $visited) {
109-
color: $normal;
110-
&:hover { color: $hover; }
111-
&:visited { color: $visited; }
112-
}
80+
接收的参数不仅可以当成 `value` 使用也可以使用插值充当 `key`
11381

114-
a {
115-
@include link-colors(blue, red, green);
116-
}
82+
也允许默认值 `@mixin replace-text($image, $x: 50%, $y: 50%)`
11783

118-
//Sass最终生成的是:
84+
传递参数时可以按顺序传递也可以按名称传递,语法与默认参数是一致的 `@include square(100px, $radius: 4px);`
11985

120-
a { color: blue; }
121-
a:hover { color: red; }
122-
a:visited { color: green; }
123-
```
124-
也可以这样传参,不需要考虑顺序
125-
```css
126-
a {
127-
@include link-colors(
128-
$normal: blue,
129-
$visited: green,
130-
$hover: red
131-
);
132-
}
133-
```
86+
除了接受参数之外,mixin 还可以接受一整块样式,即内容块。mixin 可以通过在其主体中包含 `@content` 规则来声明它接受的内容块
13487
## @extend
13588
@extend 允许你将一个选择器的 CSS 属性​​共享​​给另一个选择器,避免重复代码
13689

0 commit comments

Comments
 (0)