Menu
Coddy logo textTech

사이드바 + 콘텐츠 레이아웃

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

사이드바 + 콘텐츠 레이아웃은 메인 콘텐츠 영역과 내비게이션 또는 추가 정보를 위한 사이드바가 있는 일반적인 반응형 패턴입니다.

기본 HTML 구조로 시작합니다:

<div class="container">
  <main class="content">Main content here</main>
  <aside class="sidebar">Sidebar content here</aside>
</div>

이제 모바일 우선 접근 방식을 위한 CSS를 추가합니다:

.container {
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
}

.content {
  padding: 20px;
}

.sidebar {
  padding: 20px;
  background-color: #f5f5f5;
}

그런 다음 더 큰 화면에서 나란히 배치되는 레이아웃을 만들기 위해 미디어 쿼리를 추가합니다:

@media (min-width: 768px) {
  .container {
    flex-direction: row;
  }
  
  .content {
    flex: 3;
  }
  
  .sidebar {
    flex: 1;
  }
}

이것은 모바일에서는 수직으로 쌓이고 더 큰 화면에서는 나란히 표시되는 반응형 레이아웃을 생성합니다.

challenge icon

챌린지

쉬움

모바일 우선 접근 방식(mobile-first approach)으로 스타일이 지정된 반응형 Sidebar + Content 레이아웃이 제공됩니다.

작업 내용:

  1. 화면 너비가 768px보다 넓을 때 사이드바가 콘텐츠의 오른쪽에 나타나도록 만드세요.
  2. 더 큰 화면에서는 콘텐츠 영역에 70% width를, 사이드바에 30% width를 부여하세요.

치트 시트

Sidebar + Content 레이아웃은 flexbox를 사용하여 메인 콘텐츠 영역과 사이드바가 있는 반응형 패턴을 만듭니다.

기본 HTML 구조:

<div class="container">
  <main class="content">Main content here</main>
  <aside class="sidebar">Sidebar content here</aside>
</div>

모바일 우선 CSS 접근 방식:

.container {
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
}

.content {
  padding: 20px;
}

.sidebar {
  padding: 20px;
  background-color: #f5f5f5;
}

더 큰 화면을 위한 미디어 쿼리:

@media (min-width: 768px) {
  .container {
    flex-direction: row;
  }
  
  .content {
    flex: 3;
  }
  
  .sidebar {
    flex: 1;
  }
}

이것은 모바일에서는 수직으로 쌓이고 더 큰 화면에서는 나란히 표시되는 레이아웃을 생성합니다.

직접 해보기

<!DOCTYPE html>
<html>
<head>
  <title>Sidebar + Content Layout</title>
  <style>
    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }
    
    body {
      font-family: "Segoe UI", Arial, sans-serif;
      line-height: 1.6;
      background: #f5f7fa;
      color: #333;
    }

    .container {
      display: flex;
      flex-direction: column;
      max-width: 1100px;
      margin: 40px auto;
      background: #fff;
      border-radius: 8px;
      overflow: hidden;
      box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    }
    
    .content {
      padding: 25px;
    }

    .content h2 {
      color: #2a6592;
      margin-bottom: 15px;
    }

    .content p {
      margin-bottom: 1em;
    }
    
    .sidebar {
      padding: 25px;
      background-color: #eaf3fa;
      border-left: 3px solid #2a6592;
    }
    
    .sidebar h3 {
      margin-bottom: 15px;
      color: #2a6592;
    }

    .sidebar ul {
      list-style: none;
      padding-left: 0;
    }

    .sidebar li {
      margin: 10px 0;
    }

    .sidebar a {
      text-decoration: none;
      color: #2a6592;
      font-weight: 500;
      transition: color 0.2s;
    }

    .sidebar a:hover {
      color: #17405d;
    }

    @media (min-width: 768px) {

    }
  </style>
</head>
<body>
  <div class="container">
    <main class="content">
      <h2>Exploring Italy: A Travel Story</h2>
      <p>Italy is a country full of culture, history, and delicious food. From the romantic canals of Venice to the ancient ruins of Rome, every corner tells a story.</p>
      <p>During my trip, I explored Florence’s Renaissance art, enjoyed authentic pizza in Naples, and relaxed on the beautiful Amalfi Coast. Each city offered something unique and unforgettable.</p>
      <p>If you’re planning a trip, I recommend taking the time to explore both big cities and small villages. You’ll find hidden gems, welcoming locals, and memories that last forever.</p>
    </main>
    <aside class="sidebar">
      <h3>More Travel Guides</h3>
      <ul>
        <li><a href="#">Top 10 Things to Do in Rome</a></li>
        <li><a href="#">A Foodie’s Guide to Naples</a></li>
        <li><a href="#">Venice on a Budget</a></li>
        <li><a href="#">Best Beaches of Amalfi Coast</a></li>
      </ul>
    </aside>
  </div>
</body>
</html>
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

Practical Frontend의 모든 레슨