λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
"곡뢀" π‘Ÿπ‘’π‘π‘œπ‘Ÿπ‘‘/πΉπ‘Ÿπ‘œπ‘›π‘‘π‘’π‘›π‘‘

μ˜€λ²„μ›ŒμΉ˜ μ˜μ›… 선택 νŽ˜μ΄μ§€ λ§Œλ“€μ–΄λ³΄κΈ° - vanilla ver.

by ΰ·† Yoni ΰ·† 2022. 1. 11.
728x90

 

λ³„λ„μ˜ ν”„λ ˆμž„μ›Œν¬λ‚˜ 라이브러리 같은

μ›Ήκ°œλ°œμ„ λ„μ™€μ£ΌλŠ” λͺ¨λ“ˆμ„ μ‚¬μš©ν•˜μ§€ μ•Šκ³ 

μˆœμˆ˜ν•œ HTMLκ³Ό CSS만 μ‚¬μš©ν•˜μ—¬

μ˜€λ²„μ›ŒμΉ˜ μ˜μ›… 선택 νŽ˜μ΄μ§€λ₯Ό λ§Œλ“œλŠ” μ‹€μŠ΅μ„ μ§„ν–‰ν•΄λ³΄μ•˜λ‹€.

ν‰μ†Œμ— μ•ˆκ·Έλž˜λ„ μ˜€λ²„μ›ŒμΉ˜λ₯Ό μ’‹μ•„ν•΄μ„œ
λ§Œλ“€κ³  λ‚˜λ‹ˆ 괜히 μ§œλ¦Ών–ˆλ‹€ γ…Žγ…Ž
λ‚΄ μ΅œμ•  μΊλ¦­ν„°λŠ” λ£¨μ‹œμš° 이지둱 🐸


좜처: https://github.com/ParkYoungWoong/overwatch-hero-selector-vanilla

 

GitHub - ParkYoungWoong/overwatch-hero-selector-vanilla

Contribute to ParkYoungWoong/overwatch-hero-selector-vanilla development by creating an account on GitHub.

github.com


index.html μ½”λ“œ

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Overwatch Heroes</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reset-css@5.0.1/reset.min.css" />
  <link rel="stylesheet" href="./main.css" />
</head>
<body>
  
  <div class="container">
    <div class="heroes">
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
      <div class="hero">
        <div class="image"></div>
      </div>
    </div>
    <div class="logo">
      <img src="./images/logo_overwatch.png" alt="Overwatch">
    </div>
  </div>

</body>
</html>

main.css μ½”λ“œ

body {
  height: 100vh; /* 뷰포트의 높이 100%둜 μ„€μ • */
  background-image: url(./images/bg.jpg);
  background-size: cover; /* 더 넓은 λ„ˆλΉ„μ— 맞게 λ°°κ²½ 이미지 좜λ ₯ */
  background-repeat: no-repeat; /* λ°°κ²½ 이미지 반볡 ν•΄μ œ */
  background-attachment: fixed; /* λ°°κ²½ μ΄λ―Έμ§€λŠ” μŠ€ν¬λ‘€λ˜μ§€ μ•Šλ„λ‘ λ·°ν¬νŠΈμ— κ³ μ • */
}
.container {
  padding: 50px 0;  /* container μœ„μ•„λž˜ λ‚΄λΆ€ μ—¬λ°± μ„€μ • */
}
.container .heroes {
  display: flex; /* heroes μš”μ†Œλ“€ μˆ˜ν‰ μ •λ ¬ */
  flex-wrap: wrap; /* μ€„λ°”κΏˆ */
  justify-content: center; /* heroλ“€ κ°€μš΄λ° μ •λ ¬ */
  max-width: 700px; /* μ΅œλŒ€ λ„ˆλΉ„ μ„€μ •, κ·Έ μ΄ν•˜λŠ” μžλ™ μ •λ ¬ */
  margin: 0 auto; /* 쒌우 μ—¬λ°± μžλ™ μ„€μ •(κ°€μš΄λ° 정렬됨) */
  padding: 40px 20px; /* heroes μš”μ†Œ λ‚΄λΆ€ μ—¬λ°± μ„€μ • */
}
.container .heroes .hero {
  width: 80px;
  height: 84px;
  margin: 4px; /* μ’Œμš°μƒν•˜ μ—¬λ°± 4px둜 μ„€μ • */
  border: 3px solid #fff; /* hero 흰색 ν…Œλ‘λ¦¬ μ„  */
  border-radius: 10px; /* λͺ¨μ„œλ¦¬ λ‘₯κΈ€κ²Œ */
  box-sizing: border-box; /* border μ„€μ •μœΌλ‘œ 인해 컀진 μš”μ†Œ 쀄여주기 */
  background-color: #555;
  overflow: hidden; /* hero image λ„˜μΉ˜λŠ” μ˜μ—­ μž˜λΌλ‚΄κΈ° */
  transform: skewX(-14deg); /* -14λ„λ§ŒνΌ κΈ°μšΈμž„ */
  transition: /* μ†μ„±λ³„λ‘œ μ „ν™˜ duration λ”°λ‘œ μ„€μ • */
    transform .1s, /* μ»€μ§€λŠ” 효과 */
    background-color .6s; /* 배경색 μ „ν™˜ 효과 μ’€ 더 느리게 */
}
.container .heroes .hero:hover { /* hero에 마우슀 올리면 */
  background-color: orange; /* λ°°κ²½ 색상 orange둜 λ°”λ€œ */
  transform: skewX(-14deg) scale(1.3); /* μš”μ†Œ -14도 κΈ°μšΈμ—¬μ§„μ±„λ‘œ 1.3λ°° 컀짐 */
  z-index: 1; /* μš”μ†Œ μŒ“μž„ μˆœμ„œ μ‘°μ • */
}
.container .heroes .hero .image {
  width: 140%; /* λΆ€λͺ¨ μš”μ†ŒμΈ hero λ„ˆλΉ„μ™€μ˜ μƒλŒ€ 크기(%) */
  height: 100%;
  background-position: center; /* 이미지 κ°€μš΄λ° 배치 */
  background-repeat: no-repeat; /* 이미지 반볡 ν•΄μ œ */
  background-size: 90px; /* κ°€λ‘œ λ„ˆλΉ„ */
  transform: skewX(14deg) translateX(-16px); /* 14도 κΈ°μšΈμ—¬μ€€ 만큼 거꾸둜 기울이기, xμΆ• λ°©ν–₯으둜 -16px 만큼 이동 */
}
/* 총 32λͺ…μ˜ hero 이미지 κ°€μ Έμ˜€κΈ° */
.container .heroes .hero:nth-child(1) .image {  background-image: url(./images/hero1.png);}
.container .heroes .hero:nth-child(2) .image {  background-image: url(./images/hero2.png);}
.container .heroes .hero:nth-child(3) .image {  background-image: url(./images/hero3.png);}
.container .heroes .hero:nth-child(4) .image {  background-image: url(./images/hero4.png);}
.container .heroes .hero:nth-child(5) .image {  background-image: url(./images/hero5.png);}
.container .heroes .hero:nth-child(6) .image {  background-image: url(./images/hero6.png);}
.container .heroes .hero:nth-child(7) .image {  background-image: url(./images/hero7.png);}
.container .heroes .hero:nth-child(8) .image {  background-image: url(./images/hero8.png);}
.container .heroes .hero:nth-child(9) .image {  background-image: url(./images/hero9.png);}
.container .heroes .hero:nth-child(10) .image {  background-image: url(./images/hero10.png);}

.container .heroes .hero:nth-child(11) .image {  background-image: url(./images/hero11.png);}
.container .heroes .hero:nth-child(12) .image {  background-image: url(./images/hero12.png);}
.container .heroes .hero:nth-child(13) .image {  background-image: url(./images/hero13.png);}
.container .heroes .hero:nth-child(14) .image {  background-image: url(./images/hero14.png);}
.container .heroes .hero:nth-child(15) .image {  background-image: url(./images/hero15.png);}
.container .heroes .hero:nth-child(16) .image {  background-image: url(./images/hero16.png);}
.container .heroes .hero:nth-child(17) .image {  background-image: url(./images/hero17.png);}
.container .heroes .hero:nth-child(18) .image {  background-image: url(./images/hero18.png);}
.container .heroes .hero:nth-child(19) .image {  background-image: url(./images/hero19.png);}
.container .heroes .hero:nth-child(20) .image {  background-image: url(./images/hero20.png);}

.container .heroes .hero:nth-child(21) .image {  background-image: url(./images/hero21.png);}
.container .heroes .hero:nth-child(22) .image {  background-image: url(./images/hero22.png);}
.container .heroes .hero:nth-child(23) .image {  background-image: url(./images/hero23.png);}
.container .heroes .hero:nth-child(24) .image {  background-image: url(./images/hero24.png);}
.container .heroes .hero:nth-child(25) .image {  background-image: url(./images/hero25.png);}
.container .heroes .hero:nth-child(26) .image {  background-image: url(./images/hero26.png);}
.container .heroes .hero:nth-child(27) .image {  background-image: url(./images/hero27.png);}
.container .heroes .hero:nth-child(28) .image {  background-image: url(./images/hero28.png);}
.container .heroes .hero:nth-child(29) .image {  background-image: url(./images/hero29.png);}
.container .heroes .hero:nth-child(30) .image {  background-image: url(./images/hero30.png);}

.container .heroes .hero:nth-child(31) .image {  background-image: url(./images/hero31.png);}
.container .heroes .hero:nth-child(32) .image {  background-image: url(./images/hero32.png);}

.container .logo {
  max-width: 300px; /* logo μ΅œλŒ€ λ„ˆλΉ„ μ„€μ • */
  margin: 0 auto; /* 쒌우 μ—¬λ°± auto둜 μ„€μ •(κ°€μš΄λ°λ‘œ 정렬됨) */
  padding: 0 20px; /* logo μ’Œμš°μ—λ§Œ λ‚΄λΆ€ μ—¬λ°± μ„€μ • */
}
.container .logo img {
  width: 100%; /* logo의 300px보닀 컀질 순 μ—†μŒ */
}

ΰ·† μ΅œμ’… μ™„μ„±λœ νŽ˜μ΄μ§€ ΰ·†


μ§€κΈˆμ€ vanilla 버전이기에
32개의 이미지λ₯Ό λΆˆλŸ¬μ˜€λŠ” μ½”λ“œλ₯Ό λͺ¨λ‘
μž‘μ„±ν•΄μ€˜μ•Όν•˜λŠ” λΆˆνŽΈν•¨μ΄ μ‘΄μž¬ν–ˆλ‹€.

이λ₯Ό λ³΄μ™„ν•˜κΈ° μœ„ν•΄μ„œλŠ” SCSSλΌλŠ”
CSS μ „μ²˜λ¦¬κΈ°λ₯Ό μ‚¬μš©ν•œλ‹€λ©΄
보닀 μˆ˜μ›”ν•˜κ²Œ μ½”λ“œλ₯Ό μž‘μ„±ν•  수 있게 될 것이닀.

 

λ‹€μŒμ— SCSS 곡뢀해 μ™€μ„œ μ μš©μ‹œμΌœλ΄μ•Όμ§“-!!

✧٩(ˊ ωΛ‹*)و✧

728x90

λŒ“κΈ€