Sass
설치 및 적용
// 1. Sass 설치
npm install sass
// 2. 설치 확인
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"react-scripts": "5.0.1",
"sass": "^1.66.1",
"web-vitals": "^2.1.4"
},
import React from 'react';
import './common.scss';
문법(Syntax)
@import "reset", "common"
$primary-color: #1351f9;
.text {
color: $primary-color;
}
.parent {
font-size: 20px;
.child {
color: red;
}
}
.parent {
font-size: 20px;
&.bg-red {
background-color: yellow;
}
}
@mixin ellipsis {
display: block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.text {
@include ellipsis;
}
@mixin fontStyle ($size: 10px, $weight) {
font-size: $size;
font-weight: $weight;
}
.text1 {
@include fontStyle(400);
}
.text2 {
@include fontStyle(20px, 400);
}
.text3 {
@include fontStyle(40px, 700);
}
@mixin lineClamp ($line: 1) {
if ($line > 1) {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: $line;
overflow: hidden;
text-overflow: ellipsis;
} else {
display: block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
.text1 {
@include lineClamp();
}
.text2 {
@include lineClamp(3);
}
@function landscapeCell ($ratio) {
@return $ratio / 2;
}
.landscape-cell {
width: landscapeCell(100px);
}