๐ฆ ์จ๋ณด๋ฉ 3์ฃผ 2์ผ์ฐจ - SCSS ์ค์น ๋ฐ ์ฌ์ฉํด ๋ณด๊ธฐ
โจ03/22 : ๋ชฉํ : SCSS ์ค์น ๋ฐ ๊ธฐ๋ณธ ๋ฌธ๋ฒ ์ตํ๊ธฐ
Swiper๋ฅผ ์ด์ฉํด ์ฌ๋ผ์ด๋๋ฅผ ๊ฐ์ ธ์ค๊ณ , SCSS๋ก ์ปค์คํฐ๋ง์ด์ง ํด๋ณด์.
01 Swiper ์ฌ๋ผ์ด๋ ์ฌ์ฉํด ๋ณด๊ธฐ
1. Swiperํํ์ด์ง => Demos => ๋ชฉ๋ก ์ค์์ ์ํ๋ ์ฌ๋ผ์ด๋ ๊ฐ์ ธ์ค๊ธฐ
2. Core(html,css,js), React, Vue ๋ฑ ์ฌ๋ฌ ์ข ๋ฅ๋ก ์ฝ๋๋ฅผ ๋ณผ ์ ์๋ค.
ํด๋ฆญํ๋ฉด ์ฝ๋๊ฐ ์ญ ๋์ค๋๋ฐ ์ด ์ฝ๋๋ฅผ ๊ฐ์ธ ํ์ ์ ์ฒจ๋ถํ๋ฉด ๋๋ค.
์ฃผ์ํ ์ ์1. script๋ฅผ ์ฌ๋ฐ๋ฅด๊ฒ ๊ฐ์ ธ์๋์ง, 2.์ฌ๋ผ์ด๋๋ position ์ค์ ์ด ์ค์ํ๋ฐ, ์ฝ๋์์๋ ๋ณดํต html์ด๋ body์ relative๊ฐ ๊ฑธ๋ ค์๊ธฐ ๋๋ฌธ์ ์ํ๋ ์์์ ์ฎ๊ฒจ์ ์ ์กฐ์ ํด ์ฃผ์ด์ผ ํ๋ค.
HTML
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.css" />
<script src="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.js"></script>
<div class="slider">
<h3 class="slider-title">์ด ์ํ ์ด๋์?</h3>
<div class="swiper mySwiper">
<div class="swiper-wrapper">
<div class="swiper-slide">
<ul>
<li>
<div class="img-con">
<img src="https://product-image.kurly.com/product/image/469c0fc9-9f8d-46ae-becd-bda0098d965a.jpg" alt="product1">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[ํ์ฐํ์ฐ] 1+ ํ์ฐ ๋ฑ์ฌ 200g (๋์ฅ) 3์ข
</p>
<span class="sale sale-percent">15%</span>
<span class="sale sale-price">25,415์~</span>
<span class="price">29,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1567506396267l0.jpg" alt="product2">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ํ๋ฆฌ์ค] ํ๋ฆฌ๋ฏธ์ ์ฐฉ์ฆ ์ค๋ ์ง ํ์ธ์ ํ 2์ข
(ํ1)</p>
<span class="sale sale-price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/cdn-cgi/image/quality=85,width=676/shop/data/goods/1653037164206l0.jpg" alt="product3">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฐ์ฒด์ฝ] ์์คํธ๋ผ๋ฒ์ง ์ฌ๋ฆฌ๋ธ ์ค์ผ</p>
<span class="sale sale-percent">10%</span>
<span class="sale sale-price">10,710์~</span>
<span class="price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1657232326605l0.jpg" alt="product4">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฒ ์ด๋ฒจ์ค] ๋๋ธ๋ฐ์ดํธ ํ๋กํด๋ฐ ์นด๋ผ๋ฉ ํฌ๋ฆฌ์คํ (2์
)</p>
<span class="sale sale-percent">6%</span>
<span class="sale sale-price">9,900์</span>
<span class="price">10,600์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
</ul>
</div>
<div class="swiper-slide">
<ul>
<li>
<div class="img-con">
<img src="https://product-image.kurly.com/product/image/469c0fc9-9f8d-46ae-becd-bda0098d965a.jpg" alt="product1">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[ํ์ฐํ์ฐ] 1+ ํ์ฐ ๋ฑ์ฌ 200g (๋์ฅ) 3์ข
</p>
<span class="sale sale-percent">15%</span>
<span class="sale sale-price">25,415์~</span>
<span class="price">29,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1567506396267l0.jpg" alt="product2">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ํ๋ฆฌ์ค] ํ๋ฆฌ๋ฏธ์ ์ฐฉ์ฆ ์ค๋ ์ง ํ์ธ์ ํ 2์ข
(ํ1)</p>
<span class="sale sale-price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/cdn-cgi/image/quality=85,width=676/shop/data/goods/1653037164206l0.jpg" alt="product3">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฐ์ฒด์ฝ] ์์คํธ๋ผ๋ฒ์ง ์ฌ๋ฆฌ๋ธ ์ค์ผ</p>
<span class="sale sale-percent">10%</span>
<span class="sale sale-price">10,710์~</span>
<span class="price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1657232326605l0.jpg" alt="product4">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฒ ์ด๋ฒจ์ค] ๋๋ธ๋ฐ์ดํธ ํ๋กํด๋ฐ ์นด๋ผ๋ฉ ํฌ๋ฆฌ์คํ (2์
)</p>
<span class="sale sale-percent">6%</span>
<span class="sale sale-price">9,900์</span>
<span class="price">10,600์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
</ul>
</div>
<div class="swiper-slide">
<ul>
<li>
<div class="img-con">
<img src="https://product-image.kurly.com/product/image/469c0fc9-9f8d-46ae-becd-bda0098d965a.jpg" alt="product1">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[ํ์ฐํ์ฐ] 1+ ํ์ฐ ๋ฑ์ฌ 200g (๋์ฅ) 3์ข
</p>
<span class="sale sale-percent">15%</span>
<span class="sale sale-price">25,415์~</span>
<span class="price">29,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1567506396267l0.jpg" alt="product2">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ํ๋ฆฌ์ค] ํ๋ฆฌ๋ฏธ์ ์ฐฉ์ฆ ์ค๋ ์ง ํ์ธ์ ํ 2์ข
(ํ1)</p>
<span class="sale sale-price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/cdn-cgi/image/quality=85,width=676/shop/data/goods/1653037164206l0.jpg" alt="product3">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฐ์ฒด์ฝ] ์์คํธ๋ผ๋ฒ์ง ์ฌ๋ฆฌ๋ธ ์ค์ผ</p>
<span class="sale sale-percent">10%</span>
<span class="sale sale-price">10,710์~</span>
<span class="price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1657232326605l0.jpg" alt="product4">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฒ ์ด๋ฒจ์ค] ๋๋ธ๋ฐ์ดํธ ํ๋กํด๋ฐ ์นด๋ผ๋ฉ ํฌ๋ฆฌ์คํ (2์
)</p>
<span class="sale sale-percent">6%</span>
<span class="sale sale-price">9,900์</span>
<span class="price">10,600์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
</ul>
</div>
<div class="swiper-slide">
<ul>
<li>
<div class="img-con">
<img src="https://product-image.kurly.com/product/image/469c0fc9-9f8d-46ae-becd-bda0098d965a.jpg" alt="product1">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[ํ์ฐํ์ฐ] 1+ ํ์ฐ ๋ฑ์ฌ 200g (๋์ฅ) 3์ข
</p>
<span class="sale sale-percent">15%</span>
<span class="sale sale-price">25,415์~</span>
<span class="price">29,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1567506396267l0.jpg" alt="product2">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ํ๋ฆฌ์ค] ํ๋ฆฌ๋ฏธ์ ์ฐฉ์ฆ ์ค๋ ์ง ํ์ธ์ ํ 2์ข
(ํ1)</p>
<span class="sale sale-price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/cdn-cgi/image/quality=85,width=676/shop/data/goods/1653037164206l0.jpg" alt="product3">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฐ์ฒด์ฝ] ์์คํธ๋ผ๋ฒ์ง ์ฌ๋ฆฌ๋ธ ์ค์ผ</p>
<span class="sale sale-percent">10%</span>
<span class="sale sale-price">10,710์~</span>
<span class="price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1657232326605l0.jpg" alt="product4">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฒ ์ด๋ฒจ์ค] ๋๋ธ๋ฐ์ดํธ ํ๋กํด๋ฐ ์นด๋ผ๋ฉ ํฌ๋ฆฌ์คํ (2์
)</p>
<span class="sale sale-percent">6%</span>
<span class="sale sale-price">9,900์</span>
<span class="price">10,600์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
</ul>
</div>
<div class="swiper-slide">
<ul>
<li>
<div class="img-con">
<img src="https://product-image.kurly.com/product/image/469c0fc9-9f8d-46ae-becd-bda0098d965a.jpg" alt="product1">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[ํ์ฐํ์ฐ] 1+ ํ์ฐ ๋ฑ์ฌ 200g (๋์ฅ) 3์ข
</p>
<span class="sale sale-percent">15%</span>
<span class="sale sale-price">25,415์~</span>
<span class="price">29,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1567506396267l0.jpg" alt="product2">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ํ๋ฆฌ์ค] ํ๋ฆฌ๋ฏธ์ ์ฐฉ์ฆ ์ค๋ ์ง ํ์ธ์ ํ 2์ข
(ํ1)</p>
<span class="sale sale-price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/cdn-cgi/image/quality=85,width=676/shop/data/goods/1653037164206l0.jpg" alt="product3">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฐ์ฒด์ฝ] ์์คํธ๋ผ๋ฒ์ง ์ฌ๋ฆฌ๋ธ ์ค์ผ</p>
<span class="sale sale-percent">10%</span>
<span class="sale sale-price">10,710์~</span>
<span class="price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1657232326605l0.jpg" alt="product4">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฒ ์ด๋ฒจ์ค] ๋๋ธ๋ฐ์ดํธ ํ๋กํด๋ฐ ์นด๋ผ๋ฉ ํฌ๋ฆฌ์คํ (2์
)</p>
<span class="sale sale-percent">6%</span>
<span class="sale sale-price">9,900์</span>
<span class="price">10,600์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
</ul>
</div>
<div class="swiper-slide">
<ul>
<li>
<div class="img-con">
<img src="https://product-image.kurly.com/product/image/469c0fc9-9f8d-46ae-becd-bda0098d965a.jpg" alt="product1">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[ํ์ฐํ์ฐ] 1+ ํ์ฐ ๋ฑ์ฌ 200g (๋์ฅ) 3์ข
</p>
<span class="sale sale-percent">15%</span>
<span class="sale sale-price">25,415์~</span>
<span class="price">29,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1567506396267l0.jpg" alt="product2">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ํ๋ฆฌ์ค] ํ๋ฆฌ๋ฏธ์ ์ฐฉ์ฆ ์ค๋ ์ง ํ์ธ์ ํ 2์ข
(ํ1)</p>
<span class="sale sale-price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/cdn-cgi/image/quality=85,width=676/shop/data/goods/1653037164206l0.jpg" alt="product3">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฐ์ฒด์ฝ] ์์คํธ๋ผ๋ฒ์ง ์ฌ๋ฆฌ๋ธ ์ค์ผ</p>
<span class="sale sale-percent">10%</span>
<span class="sale sale-price">10,710์~</span>
<span class="price">11,900์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
<li>
<div class="img-con">
<img src="https://img-cf.kurly.com/shop/data/goods/1657232326605l0.jpg" alt="product4">
<i class="cart fa-solid fa-cart-plus"></i>
</div>
<div class="details">
<p class="title">[๋ฒ ์ด๋ฒจ์ค] ๋๋ธ๋ฐ์ดํธ ํ๋กํด๋ฐ ์นด๋ผ๋ฉ ํฌ๋ฆฌ์คํ (2์
)</p>
<span class="sale sale-percent">6%</span>
<span class="sale sale-price">9,900์</span>
<span class="price">10,600์</span>
<span class="review"><i class="fa-regular fa-comment-dots"></i>ํ๊ธฐ 999+</span>
</div>
</li>
</ul>
</div>
</div>
<div class="swiper-button swiper-button-next"></div>
<div class="swiper-button swiper-button-prev"></div>
</div>
</div>
<script>
let swiper = new Swiper(".mySwiper", {
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
});
</script>
- ์ฌ๋ผ์ด๋ ์ ์์ ํ์ดํ ๋ฒํผ์ ๊ธฐ๋ณธ์ ์ผ๋ก ::afterํ๊ทธ์ ์คํ์ผ์ด ๋ค์ด๊ฐ ์๋ค. ํ์ ์ CSS์์ ํด๋น ๋ฒํผ์ ์คํ์ผ์ ์กฐ์ ํ๊ฑฐ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ค์ด๊ฐ์๋ ๊ฐ์ํ๊ทธ์ ์คํ์ผ์ ์กฐ์ ํด ์ฃผ๋ฉด ๋๋ค.
02 SCSS ์ฌ์ฉํด ๋ณด๊ธฐ
1. SCSS ํด๋ ๊ตฌ์กฐ
- CSS์ SCSSํด๋ ๋ฐ๋ก ์์ฑ => ์์ ์ปดํ์ผ๋ CSSํ์ผ์ CSSํด๋์ ์ ์ฅ๋๋๋ก ํด๋จ๋ค.
SCSSํ์ผ์ ์๋ฒ์์ ๋ถํ์ํ๋ฏ๋ก ๋น๋์์ ์ ์ธ๋๋๋ก ์ค์ ํ๋ค.
2. _reset.scss / _variable.scss
_๊ฐ ๋ค์ด๊ฐ ํ์ผ์ scss์์ css๋ก ๋ณํํ๋ ์์ ์ ๋ฌด์ํ๊ฒ ํด์ฃผ๋ ์ญํ ์ ํ๋ค. ๋ฐ๋ผ์ scssํ์ผ ์ด๋ฆ ์์ _(์ธ๋๋ฐ)๋ฅผ ๋ฃ์ด์ฃผ๋ฉด cssํด๋์ ํด๋น ํ์ผ์ด ์ถ๊ฐ๋์ง ์๋๋ค.
_reset.scss => ์ด๊ธฐ์ค์ ํ์ผ
@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@100;300;400;500;700;900&display=swap");
* {
margin: 0;
padding: 0;
font-family: "Noto Sans KR", sans-serif;
}
ul,
li {
list-style: none;
}
button,
input {
border: none;
background-color: transparent;
cursor: pointer;
}
- variable => color, ๋ณ์์ค์ ํ์ผ => ๋์ค์ color๋ font๋ ๋ฐ๋ก ํ์ผ๋ก ๊ตฌ์ฑํด ๋๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค.
$color-purple: #5f0080;
$color-gray: #dddddd;
$color-light-gray: #f0f0f0;
$color-dark-gray: #424242;
$color-white: #fff;
@mixin flex-space-between {
display: flex;
justify-content: space-between;
}
@mixin flex-all-center {
display: flex;
justify-content: center;
align-items: center;
}
3. importํด์ ์ฌ์ฉ
@import "./reset";
@import "./variable";
- @include : @mixin๋ณ์ ๊ฐ์ ธ์ค๊ธฐ
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
@include flex-all-center;
}
- & :hover, active, checked, focus, ๋ฑ๋ฑ => ๋ถ๋ชจ์ ํน์ ํจ๊ณผ ์ ์ฌ์ฉ
.checkbox {
display: none;
&:checked + .custom-check {
width: 20px;
line-height: 20px;
font-size: 13px;
text-align: center;
color: $color-white;
background-color: rgb(255, 187, 0);
}
}
โ์ถ๊ฐ์ ์ผ๋ก, SCSS์์ ์คํ์ผ์ด ์ ๋จนํ์ง ์์ ๊ฒฝ์ฐ, 1. Watching์ด ์ ๋๊ณ ์๋์ง, 2. output ํฐ๋ฏธ๋ ์ฐฝ์ ์๋ฌ๊ฐ ๋ ๊ณณ์ด ์๋์ง๋ฅผ ์ ํ์ธํด ๋ณด์...(์ ์คํ์ผ์ด ์๋จน๋์ง ๋ชฐ๋ผ์ ๊ณ์ ์ ๋จน์๋ค.)
์์ง ์ ์ฌ์ฉํ๊ณ ์๋์ง๋ ์ ๋ชจ๋ฅด๊ฒ ์ง๋ง ๊ณ์ ์ฌ์ฉํ๋ฉด์ ์ฐ์ตํ๋ค ๋ณด๋ฉด ๋ ๋ฐฐ์ธ ์ ์ด ๋ง์ ๊ฒ ๊ฐ๋ค!๐คญ