๐ฅ ์ฃผ์์
- ํฐ๋ฐ์ดํ ์ฌ์ฉ! (convention ๋๋ฌธ๊ณผ ํน์ ๋ชจ๋ฅผ ์ค๋ฅ)
์ถ์ฒ ์ฌ์ดํธ
scss ๊ฐ css ๋ก ๋ณํ๋ ์ฝ๋๋ฅผ ๋ฐ๋ก ํ์ธํ ์ ์๋ ์ฌ์ดํธ
SassMeister | The Sass Playground!
SassMeister: The sassiest way to play with Sass, Compass, & LibSass! Loading...
www.sassmeister.com
- scss ๊ณต์ ์ฌ์ดํธ ๋ชจ๋
https://sass-lang.com/documentation/modules
Sass: Built-In Modules
Compatibility: Dart Sass since 1.23.0 LibSass โ Ruby Sass โ Only Dart Sass currently supports loading built-in modules with @use. Users of other implementations must call functions using their global names instead. Sass provides many built-in modules w
sass-lang.com
Sass: Built-In Modules
Compatibility: Dart Sass since 1.23.0 LibSass โ Ruby Sass โ Only Dart Sass currently supports loading built-in modules with @use. Users of other implementations must call functions using their global names instead. Sass provides many built-in modules w
sass-lang.com
์ฃผ์
// css๋ก ์ปดํ์ผํ๋ฉด ์ฌ๋ผ์ง
/**/ ์ปดํ์ผํด๋ ์ฌ๋ผ์ง์ง ์์
์ค์ฒฉ
/*css*/
.container ul li{
font-size: 40px;
}
.container ul li .name{
color: royalblue;
}
.container ul li .age{
color: orange;
}
/*scss*/
.container{
ul{
li{
font-size: 40px;
.name{
color: royalblue;
}
.age{
color: orange;
}
}
}
์์ ์ ํ์ ์ฐธ์กฐ
&: ์ ํผ์ผ๋๊ฐ ํฌํจ๋์ด ์๋ ๋ฒ์์ ์์์ ํ์๋ฅผ ์ฐธ์กฐ / ์์์ ํ์๊ฐ ์ ํผ์ผ๋๋ก ์นํ
/*css*/
.list li:last-childI
margin-right: 0;
/*scss*/
.list{
li{
&:last-child{
margin-right: 0;
}
}
}
์ค์ฒฉ๋ ์์ฑ
๋ค์์คํ์ด์ค : ์ด๋ฆ์ ํตํด ๊ตฌ๋ถ ๊ฐ๋ฅํ ๋ฒ์๋ฅผ ๋ง๋ค์ด๋ด๋ ๊ฒ (์ผ์ข ์ ์ ํจใ ๋จธ์๋ฅผ ์ง์ ํ๋ ๋ฐฉ๋ฒ)
/*css*/
.box{
/*font- ์ ๋ค์์คํ์ด์ค*/
font-weight: bold;
font-size: 10px;
font-family: sans-serif;
margin-top: 10px;
margin-left: 20px;
padding-top: 10px;
padding-bottom: 40px;
padding-left: 20px;
padding-right: 30px;
}
/*scss*/
.box{
font:{
weight: bold;
size: 10px;
family: sans-serif;
};
margin:{
top: 10px;
left: 20px;
};
padding:{
top: 10px;
bottom: 40px;
left: 20px;
right: 30px;
};
}
๊ธฐ๋ณธ๊ฐ !default
๊ธฐ๋ณธ๊ฐ์ ์ง์ ํด๋์ง๋ง ์ฌ์ฉ์๊ฐ ์๋ก ์ง์ ํ๋ฉด ๊ทธ ๊ฐ์ ์ฌ์ฉํ๋ผ
$primary: red; !default
.serch{
$primary: blue;
background-color: $primary; /*blue*/
}
๋ณ์ (Variables)
$๋ณ์๋ช : ๊ฐ;
๋ธ๋ญ๋ ๋ฒจ ์ ํจ๋ฒ์๊ฐ ์์
/*css*/
.container{
position: fixed;
top: 200px;
/*size์ ๊ฐ์ด ์ฌํ ๋น ๋์๊ธฐ ๋๋ฌธ์ ๋ฐ๋ ๊ฐ์ผ๋ก ์ค์ */
left: 100px;
}
.container .item{
width: 200px;
height: 200px;
transform: translateX(200px);
}
/*scss*/
$size: 200px;
.container{
position: fixed;
top: $size;
.item{
$size: 100px;
width: $size;
height: $size;
transform: translateX($size);
}
left: $size;
}
์ฐ์ ์ฐ์ฐ
๋๋๊ธฐ ๊ธฐํธ์ธ / ๋ font ๋จ์ถ์์ฑ์ ๊ตฌ๋ถ์๋ก ์ฌ์ฉํจ์ผ๋ก ์๋์ ๋ฐฉ๋ฒ์ ์จ์ผํจ
1 () ์๊ดํธ๋ก ๊ฐ์ธ๊ธฐ
2 ๋ณ์๋ฅผ ์ฌ์ฉ
3 ๋ค๋ฅธ ์ฐ์ฐ์์ ์ฌ์ฉํ๊ธฐ
/*css*/
div{
width: 40px;
height: 30px;
font-size: 20px;
margin: 11px;
padding: 6px;
}
/*scss*/
div {
sizer 30px;
width: 20px+20px;
height: 40p
font-size: Nopx*2;
10px;
margin: (10px+12px)/2; ///
padding: 20px%7;
}
๋ค๋ฅธ ๋จ์ ์ฐ์ ์ฐ์ฐ
width: calc(100%- 200px)
: 100% ์์ 200px ๋ฅผ ๋บ ๋งํผ์ ๋๋น
@mixin
: ์ฌ๋ฌ ์ค์ ์ฝ๋๋ฅผ ํ๋ฒ์ ๋ด์ ์ฌ์ฌ์ฉ
vs ๋ณ์ ํ๋์ ๋ณ์์๋ ํ๋์ ๊ฐ๋ง ์ฌ์ฉ
์์ฑ: @mixin ์ด๋ฆ
์ฌ์ฉ: @ include ์ด๋ฆ
/*css*/
.container{
display: flex;
justify-content: center;
align-items: center;
}
.container.item{
display: flex;
justify-content: center;
align-items: center;
}
.box{
display: flex;
justify-content: center;
align-items: center;
}
/*scss*/
@mixin çenter{ //์์ฑ
disptay flex;
justify-content: center;
align-items: center;
}
.container{
@include center; // ์ฌ์ฉ
item{
@include center;
}
}
.box{
@include center;
}
์ธ์ ์ฌ์ฉ
/*css*/
.container{
width: 200px;
height: 200px;
background-color: tomato;
}
.container .item{
width: 100px;
height: 100px;
background-color: tomato;
}
.box{
width: 100px;
height: 100px;
background-color: tomato;
}
/*scss*/
@mixin box ($size){
width: $size;
height: $size;
background-color: tomato;
}
.container{
@include box(200px)
.item{
@include box(100px);
}
}
.box{
@include box(100px);
}
์ธ์์ ๊ธฐ๋ณธ๊ฐ ์ง์
- ๊ธฐ๋ณธ๊ฐ์ ์ฌ์ฉํ ๊ฒฝ์ฐ ์ธ์ ์๊ฐน
- ํค์๋ ์ธ์: ์ธ์๋ ๋งค๊ฐ๋ณ์์ ์์๋๋ก ๋งค์นญ๋๊ธฐ ๋๋ฌธ์ ๊ฐ์ ๋ฃ์ ์ธ์๋ฅผ ํค์๋๋ก ์ง์ ์ ์ผ๋ก ์ง์ ํด์ค
/*scss ๊ธฐ๋ณธ๊ฐ ์ง์ */
@mixin box ($size: 80px, $color: tomato){
width: $size;
height: $size;
background-color: tomato;
}
.container{
@include box(200px,red)
.item{
@include box; // ๊ธฐ๋ณธ๊ฐ์ ์ฌ์ฉํ ๊ฒฝ์ฐ ์ธ์ ์๋ต
}
}
.box{
@include box($color: green); // ํค์๋ ์ธ์: ๊ฐ์ ๋ฃ์ ์ธ์๋ฅผ ์ง์ ์ ์ผ๋ก ์ง์
}
/*css*/
.container{
width: 200px;
height: 200px;
background-color: red;
.container jtem{
width:(80px;
height 80px
background-cólor: tomato;
.box{
width: 80px;
height: 80px;
background-color: green;
@content
@ mixin ์ ์ถ๊ฐ ๋ด์ฉ์ด ์์ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ
/*css*/
.container{
width: 100px;
height: 100px;
position: absolute;
top: 0;
left: 0;
}
.box{
width: 200px;
height: 300px;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
}
/*scss*/
@mixin left-top{
position: absolute;
top: 0;
left: 0;
@content;
}
.container{
width: 100px;
height: 100px;
@include left-top;
}
.box{
width: 200px;
height: 300px;
@include left-top{
bottom: 0;
right: 0;
margin: auto;
}
}
๋ฐ๋ณต๋ฌธ
๋ณด๊ฐ๋ฒ #{} vs javascript ${}
์ ๋ก ๋ฒ ์ด์ค๋๊ฐ ์๋
//js
for (let i = 0; i < 10; i += 1){
console.logCloop-${i}`)
}
/*scss*/
@for $i from 1 through 10{
box:nth-child(#{$i}){ // ๊ฐ์ ์ ๋ ๋ถ๋ถ์ด ์๋๋ผ์ ๋ณด๊ฐ๋ฒ ์ฌ์ฉ
width: 100px * $i ; //๊ฐ์ ๋ช
์ํ๋ ๋ถ๋ถ์ด๋ฏ๋ก ๊ทธ๋๋ก ์ ์
}
}
@each
list data
: list ์ ์์ ์๋ ํญ๋ชฉ๋ค์ c ๋ผ๋ ๋งค๊ฐ๋ณ์๋ก ๋ฐ์์ ์ฐจ๋ก๋๋ก {} ์์์ ์ฒ๋ฆฌ
/*css*/
.box{
color: orange;
}
.box{
color: royalblue;
}
.box{
color: yellow;
}
/*scss*/
$list: orange, royalblue, yellow;
@each $c in $list{
.box{
color: $c;
}
}
map data
: key์ value ๊ฐ ์๊ธฐ ๋๋ฌธ์ each ๋ค์์ ๋๊ฐ์ ๋งค๊ฐ๋ณ์๋ฅผ ์ ์ด์ผํจ
/*css*/
.box-o {
colork orange;
}
.box-r {
co tor royalblue;
}
.bpx-y {
kolor yellow;
}
/*scss*/
$map:(
o: orange,
r: royalblue,
y: yellow
);
@each $k, $v in $map{
.box-#{$k}{
color: $v;
}
}
ํจ์
: ์ด๋ค ๊ฐ์ ์ฐ์ฐํ์ฌ ๋ฐํํ์ฌ ์ฌ์ฉ
vs @mixin ์ ์คํ์ผ ์ ์ ์ฝ๋์ ๋ชจ์
/*css*/
.box{
width: 160px;
height: 90px;
display: flex;
justify-content: center;
align-items: center;
}
/*scss*/
@mixin center{
display: flex;
justify-content: center;
align-items: center;
}
@function ratio($size, $ratio){
@return $size*$ratio
}
.box{
$width: 160px;
width: $width;
height: ratio($width, 9/16);
@include center;
}
์์ ๋ด์ฅ ํจ์
mix(color1, color2) : color1 ๊ณผ color2 ๋ฅผ ์์
lighten(color , %) : ์์์ ๋ฐ๊ธฐ๋ฅผ %๋งํผ ๋์
darken(color , %) : ์์์ ๋ฐ๊ธฐ๋ฅผ %๋งํผ ๋ฎ์ถค
saturate(color , %) : ์์์ ์ฑ๋๋ฅผ %๋งํผ ๋์
desaturate(color , %) : ์์์ ์ฑ๋๋ฅผ %๋งํผ ๋ฎ์ถค
grayscale(color) : ์์์ ํ์์ ๋ณ๊ฒฝ
invert(color) : ์์์ ๋ฐ์
rgba(color, ํฌ๋ช ๋) : vs css rgba(๋ ๋, ๊ทธ๋ฆฐ, ๋ธ๋ฃจ, ํฌ๋ช ๋)
๊ฐ์ ธ์ค๊ธฐ
url ์๋ต๊ฐ๋ฅ
ํ์ฅ์ ์๋ต๊ฐ๋ฅ
์ฌ๋ฌ๊ฐ ๊ฐ์ ธ์ค๊ธฐ ๊ฐ๋ฅ
/*css*/
@import url("./sub.scss")
/*scss*/
@import "./su1", "./sub2"
๋ฐ์ดํฐ ์ข ๋ฅ
number: 1; // .5, 100px, lem
string: bold; // relative, "../images/a.png"
color: red; // blue, #FFFF00, rgba(0, 0,0,.1)
boolean: true; // false
null ๊ฐ์ ์ฃผ๋ฉด ์ถ๋ ฅ๋์ง ์์
null: null;
js ์ ๋ฐฐ์ด ๋ฐ์ดํฐ
list: orange, royalblue, yellow;
js ์ ๊ฐ์ฒด ๋ฐ์ดํฐ
map:(
o: orange,
r: royalblue,
y: yellow
);
'๐ป dev > ๐ฉ๐ปโ๐ป ํํ ํฌ ํ๋ก ํธ์๋ ๊ฐ๋ฐ์ ๊ณผ์ ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[GIT] git ์ทจ์ (0) | 2022.05.26 |
---|---|
[GIT] remote ์ ์ฅ์ (0) | 2022.05.10 |
[Project] css ํด๋ก ์ฝ๋ฉ (0) | 2022.04.29 |
[JS] ํ์ค ๋ด์ฅ ๊ฐ์ฒด (์ ๋ฐ์ดํธ ์์ ) (0) | 2022.04.25 |
[220419] JS function (1) | 2022.04.19 |