Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 이미지반응형
- 동적객체
- legacy-peer
- vscode git clone
- 정적객체
- googleicon
- window 정책변경
- 의존성문제
- Git clone
- git lab clone
- 단어단위로떨어지기
- 글자들여쓰기
- npm start
- node 오류
- 그누보드반응형
- slickslider
- npm install
- react npm install
- XEIcon
- package.json
- npm install 문제
- maxwidth
- 웹아이콘
- fontawesome
- owlcarousel
- MediaQuery
- 플러그인
- minwidth
- 아이콘사용법
- node설치
Archives
- Today
- Total
어쩌다 알게 된 ƪ(•̃͡•̃͡ ƪ
[Bootstrap] &self: &; @mixin 사용 scss 본문
728x90
👩🏻 알고 싶은 코드
.navigation {
$self: &;
@mixin menu-item-visible($count) {
.navigation.navigation-menu .navigation-item-more .navigation &:nth-child(-n + #{$count}),
.navigation.navigation-menu > &:nth-child(n + #{$count + 1}) {
display: none;
}
// stylelint-disable selector-max-specificity
// stylelint-disable selector-max-class
.navigation.navigation-menu > &.navigation-item-more {
display: none;
&:nth-child(n + #{$count + 2}) {
display: list-item;
}
}
// stylelint-enable selector-max-specificity
// stylelint-enable selector-max-class
}
padding: 0;
margin: 0;
list-style: none;
❓ $self: &; 쓰는 이유?
@mixin 안쪽에서 현재 선택자 .navigation을 명시적으로 써야 할 일이 있는데, scss에서는 &를 mixin 내부에서 바로 사용할 수 없을 때가 있어서 바깥의 &(상위 선택자)를 $self 변수에 저장해두고 mixin안에서 사용
=> 현재 $self == '.navigation' 를 가리킨다.
📚 해석
& 자리에 $self 즉, .navigation을 넣는 것
간단한 예시)
.navigation {
$self: &;
.wrapper #{$self} { // 즉, .wrapper .navigation 이 됨
}
}
👩🏻 알고 싶은 코드 예시)
.navigation {
$self: &; // == '.navigation'
@mixin menu-item-visible($count) {
.navigation.navigation-menu .navigation-item-more .navigation &:nth-child(-n + #{$count}),
.navigation.navigation-menu > &:nth-child(n + #{$count + 1}) {
display: none;
}
.navigation.navigation-menu > &.navigation-item-more {
display: none;
&:nth-child(n + #{$count + 2}) {
display: list-item;
}
}
}
}
를 하단처럼 사용했을 때 ($count를 5라고 가정)
.navigation {
$self: &;
@include menu-item-visible(5);
}
일 때 컴파일되면 나오는 css 👇
.navigation.navigation-menu .navigation-item-more .navigation .navigation:nth-child(-n + 5),
.navigation.navigation-menu > .navigation:nth-child(n + 6) {
display: none;
}
.navigation.navigation-menu > .navigation.navigation-item-more {
display: none;
}
.navigation.navigation-menu > .navigation.navigation-item-more:nth-child(n + 7) {
display: list-item;
}
❗❗ 이와 같이 @include menu-item-visible(숫자) 이렇게 호출해야지만 작동하는 scss mixin 코드!
728x90
'CSS > Bootstrap' 카테고리의 다른 글
| [Bootstrap] SCSS 변수 찾기, rfs() 가 뭔가? (1) | 2025.04.09 |
|---|---|
| [Bootstrap] @use 'sass:map'; map.get(), map-get(), map-deep-get() (0) | 2025.04.08 |
| [Bootstrap] @use 'sass:list'; / Dart Sass(모듈 시스템) 사용법 (0) | 2025.04.08 |
| [Bootstrap] $self: &; 중첩 구조에서의 사용 #{$self} (0) | 2025.04.08 |
| [React] Bootstrap scss v5.1.3 (1) | 2025.04.07 |
Comments