728x90
https://seokzin.tistory.com/entry/SCSS-SCSS-%EB%AC%B8%EB%B2%95-%EC%A0%95%EB%A6%AC
7. 함수 (Function)
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>프로필 섹션 페이지</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="box_group">
<div class="box1">박스 1</div>
<div class="box2">박스 2</div>
<div class="box3">박스 3</div>
</div>
</body>
</html>
$max-width: 100%;
// 부트스트랩 그리드 시스템처럼 12개의 컬럼 중에서 특정 비율만큼 가져감
@function columns($number: 1, $columns: 12){
@return $max-width * ($number / $columns);
}
.box_group{
width: $max-width;
background-color: #eee;
.box1{
width: columns(); // col-1
background-color: orange;
}
.box2{
width: columns(8); // col-8
background: red;
}
.box3{
width: columns(3); // col-3
background: blue;
}
}
8. 조건(Condition)
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>프로필 섹션 페이지</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="box-1">박스 1</div>
<div class="box-2">박스 2</div>
<div class="box-3">박스 3</div>
<div class="box-4">박스 4</div>
</body>
</html>
$width-1: 555px;
$width-2: 700px;
$width-3: 250px;
$width-4: 70px;
$limit: 300px;
.box{
&-1{
width: if($width-1 > $limit, $width-1, 30px); // 555
background: brown;
}
&-2{
width: if($width-2 > $limit, $width-2, 30px); // 700
background: yellow;
}
&-3{
width: if($width-3 > $limit, $width-3, 30px); // 30
background: green;
}
&-4{
width: if($width-4 > $limit, $width-4, 30px); // 30
background: pink;
}
}
9. @if ~ @else if ~ @else 조건문
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>프로필 섹션 페이지</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="box-1">사과</div>
<div class="box-2">바나나</div>
<div class="box-3">망고</div>
<div class="box-4">딸기</div>
</body>
</html>
$color-1: "apple";
$color-2: "banana";
$color-3: "mango";
$color-4: "strawberry";
$width-1: 555px;
$width-2: 700px;
$width-3: 250px;
$width-4: 70px;
$limit: 300px;
@mixin selectColor($fruit){
@if $fruit == "apple"{
background-color: green;
}@else if $fruit == "banana"{
background-color: yellow;
}@else if $fruit == "mango"{
background-color: orange;
}@else{
background-color: red;
}
}
.box{
&-1{
width: if($width-1 > $limit, $width-1, 30px); // 555
@include selectColor($color-1);
}
&-2{
width: if($width-2 > $limit, $width-2, 30px); // 700
@include selectColor($color-2);
}
&-3{
width: if($width-3 > $limit, $width-3, 30px); // 30
@include selectColor($color-3);
}
&-4{
width: if($width-4 > $limit, $width-4, 30px); // 30
@include selectColor($color-4);
}
}
10. @for 반복문
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>프로필 섹션 페이지</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="through">박스 1</div>
<div class="through">박스 2</div>
<div class="through">박스 3</div>
<div class="to">박스 4</div>
<div class="to">박스 5</div>
</body>
</html>
$mb: .2rem;
$default-width: 50px;
$default-color: #fff;
@for $i from 1 through 3{
.through:nth-child(#{$i}){
width: $default-width * $i;
background-color: brown;
color: $default-color;
margin-bottom: $mb;
}
}
@for $i from 4 to 6{
.to:nth-child(#{$i}){
width: $default-width * $i;
background-color: skyblue;
color: $default-color;
margin-bottom: $mb;
}
}
11. @each ~ in
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>프로필 섹션 페이지</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="puma-icon">박스 1</div>
<div class="sea-slug-icon">박스 2</div>
<div class="egret-icon">박스 3</div>
<div class="salamander-icon">박스 4</div>
<h1>큰 글씨</h1>
<h2>중간 글씨</h2>
<h3>작은 글씨</h3>
</body>
</html>
// List
@each $animal in puma, sea-slug, egret, salamander{
.#{$animal}-icon{
background-image: url(images/#{$animal}.jpg);
width: 20%; height: 300px;
background-size: cover;
background-position: center;
}
}
// Map
@each $key, $value in (h1: 2rem, h2: 1.5rem, h3: 1.2rem){
#{$key}{
font-size: $value;
}
}
728x90
'프론트엔드 > CSS' 카테고리의 다른 글
슬라이드 이미지 중앙에서 확대하기 (1) | 2024.02.24 |
---|---|
position 기본개념 (0) | 2024.02.12 |
부트스트랩 5 자주 쓰는 클래스 정리 (0) | 2023.07.14 |
position 문제 (0) | 2023.07.04 |
table table-cell 속성을 이용하여 수평으로 나열하기 (0) | 2023.06.24 |