๐บ๋ฌธ์
- @include ์ ์ธ ํ ์ถ๊ฐ ์คํ์ผ ์ง์ ์ด ์๋จ.
- parent์ child ์คํ์ผ ์ง์ ์๋จ.
.parent {
@include mix() {
// ์คํ์ผ์ง์
} (
// Error
)
// Error
.child {
}
}
html ๊ตฌ์กฐ
<div class="position-wrapper">
<div class="box1">BOX1</div>
<div class="box2">BOX2</div>
<div class="box3">BOX3</div>
</div>
@mixin
@mixin ๋ฏน์ค์ธ์ด๋ฆ($๋งค๊ฐ๋ณ์: ๊ธฐ๋ณธ๊ฐ) {
์คํ์ผ;
}
@include ๋ฏน์ค์ธ์ด๋ฆ(์ธ์);
@content
@mixin ๋ฏน์ค์ธ์ด๋ฆ() {
์คํ์ผ;
@content;
}
@include ๋ฏน์ค์ธ์ด๋ฆ() {
// ์คํ์ผ๋ธ๋ก
์คํ์ผ;
}
@mixin position(
$p: absolute;
$t: null,
$b: null,
$l: null,
$r: null
) {
position: $p;
top: $t;
bottom: $b;
left: $l;
right: $r;
// @content ๋ฃ์ด์ค์ผ ์คํ์ผ ์ถ๊ฐ ๊ฐ๋ฅ.
@content;
}
.position-wrapper {
@include position(
$p: relative;
$t: 0px;
$l: 0px;
) {
border: 1px solid #000;
width: 500px;
height: 150px;
}
div {
float: left;
width: 50px;
height: 50px;
background: gold;
&.box2 {
@inlcude position (
$t: 0px,
$l: 0px
) {
transform: translate(-50%, -50%);
}
}
&.box3 {
@include position (
$b: 0px;
$r: 0px;
)
}
}
}
/* CSS */
.position-wrapper {
position: relative;
top: 0px;
left: 0px;
border: 1px solid #000;
width: 500px;
height: 150px;
}
.position-wrapper::after {
display: block;
content: "";
clear: both;
}
.position-wrapper div {
float: left;
width: 50px;
height: 50px;
background-color: gold;
}
.position-wrapper div.box2 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.position-wrapper div.box3 {
position: absolute;
bottom: 0px;
right: 0px;
}
@mixin์์ @content๋ฅผ ๋ฃ์ด์ผ @include์์์ ์คํ์ผ ์ถ๊ฐ๊ฐ ๊ฐ๋ฅํ๋ค.