Menu
Coddy logo textTech

초콜릿 갤러리 그리드

Coddy HTML 여정의 Practical Frontend 섹션에 포함된 레슨 — 35개 중 33번째.

challenge icon

챌린지

쉬움

초콜릿 제품 갤러리를 위한 HTML이 제공됩니다. 여러분의 작업은 갤러리가 모든 화면 크기에서 멋지게 보이고 잘 작동하도록 CSS를 완성하는 것입니다. 현재는 1개 열(모바일 우선)의 그리드로 설정되어 있습니다.

수행할 작업:

  1. grid-template-columns를 사용하여 레이아웃을 위한 CSS Grid를 설정하세요:
    1. 태블릿(min-width: 600px)에서는 2개 열
    2. 데스크톱(min-width: 900px)에서는 3개 열
  2. 카드 중 하나에 “Best Seller”라고 적힌 배지를 추가하고 오른쪽 상단 모서리에 배치하세요. 카드 내부에 badge 클래스를 가진 <div>를 사용하세요.

직접 해보기

<!DOCTYPE html>
<html>
<head>
  <title>Chocolate Gallery Grid</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 20px;
      background-color: #f8f5f2;
    }

    h1 {
      text-align: center;
      margin-bottom: 20px;
      color: #4e342e;
    }

    .gallery {
      display: grid;
      grid-template-columns: 1fr;
      gap: 20px;
    }

    /* Tablet layout */
  
    /* Desktop layout */

    .card {
      position: relative;
      background: white;
      border-radius: 12px;
      box-shadow: 0 2px 6px rgba(0,0,0,0.1);
      overflow: hidden;
      transition: transform 0.2s ease;
    }

    .card:hover {
      transform: translateY(-5px);
    }

    .card img {
      width: 100%;
      height: 200px;
      object-fit: cover;
    }

    .card-content {
      padding: 15px;
    }

    .card h3 {
      margin: 0 0 10px;
      color: #3e2723;
    }

    .card p {
      font-size: 14px;
      color: #555;
      margin-bottom: 15px;
    }

    .card button {
      padding: 10px 15px;
      border: none;
      background: #6d4c41;
      color: white;
      border-radius: 6px;
      cursor: pointer;
      transition: background 0.3s;
    }

    .card button:hover {
      background: #4e342e;
    }

    /* Badge */
    .badge {
      position: absolute;
      top: 10px;
      right: 10px;
      background: #ff7043;
      color: white;
      font-size: 12px;
      font-weight: bold;
      padding: 5px 8px;
      border-radius: 12px;
      box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }
  </style>
</head>
<body>
  <h1>Chocolate Gallery</h1>

  <div class="gallery">
    <div class="card">
      <img src="https://upload.wikimedia.org/wikipedia/commons/7/71/Ritter_Sport_dark_chocolate.jpg" alt="Dark Chocolate">
      <div class="card-content">
        <h3>Dark Chocolate</h3>
        <p>Rich and intense flavor, perfect for true chocolate lovers.</p>
        <button>Buy Now</button>
      </div>
    </div>

    <div class="card">
      <img src="https://upload.wikimedia.org/wikipedia/commons/9/90/Milka_Alpine_Milk_Chocolate_bar_100g.jpg" alt="Milk Chocolate">
      <div class="card-content">
        <h3>Milk Chocolate</h3>
        <p>Creamy and sweet, the classic favorite for all ages.</p>
        <button>Buy Now</button>
      </div>
    </div>

    <div class="card">
      <img src="https://upload.wikimedia.org/wikipedia/commons/2/2b/White_chocolate_with_rose_petals.jpg" alt="White Chocolate">
      <div class="card-content">
        <h3>White Chocolate</h3>
        <p>Smooth and buttery, with a delicate vanilla flavor.</p>
        <button>Buy Now</button>
      </div>
    </div>
  </div>
</body>
</html>

Practical Frontend의 모든 레슨