-
Notifications
You must be signed in to change notification settings - Fork 2
/
outside.scss
44 lines (35 loc) · 1.06 KB
/
outside.scss
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// 원본 링크 : https://pantaley.com/blog/Add-class-to-the-most-outer-selector-using-Sass-mixin/
@mixin most-outer-selector($new-class) {
$current-selector: &;
$new-selector: [];
@each $item in $current-selector {
$first-item: nth($item, 1);
$appended-item: $first-item + $new-class;
$new-item: set-nth($item, 1, $appended-item);
$new-selector: append($new-item, $new-selector);
}
@at-root #{$new-selector} {
@content;
}
}
.parent {
.child {
span {
@include most-outer-selector('.bold') {
font-weight: bold;
}
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
<!-- example 1 -->
<div class="parent">
<div class="child"><span>Hello World<span></div>
</div>
<!-- example 2 -->
<div class="parent bold">
<div class="child"><span>Hello World<span></div>
</div>
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
.parent class의 bold가 있으면 font-weight bold
most-outer-selector가 선언된 최상위의 & 클래스 구분.