HTML/CSS 6.2 · 6부. 종합 프로젝트
소개 랜딩
구역이 여럿인 화면입니다. 바탕은 끝까지, 글은 가운데로 둡니다.
개념 설명
여러 구역이 있는 화면
6.1 은 한 덩어리였습니다. 이번에는 구역이 여럿인 화면을 만듭니다 — 머리 화면 · 기능 목록 · 문의 폼 · 꼬리말.
구역이 늘면 구역마다 폭을 어떻게 맞출지가 문제가 됩니다. 바탕색은 화면 끝까지 가고 글은 가운데로 모여야 합니다.
최소 예제 · 편집 가능
완성본
<header class="bar"> <div class="wrap bar-in"> <strong>마야 도서관</strong> <nav><a href="#join">문의</a></nav> </div> </header> <section class="hero"> <div class="wrap"> <h1>책을 빌리고 자리를 예약합니다</h1> <p>회원이면 누구나 이용할 수 있습니다.</p> <a class="btn" href="#join">문의하기</a> </div> </section> <section class="wrap"> <h2>이런 것을 할 수 있습니다</h2> <div class="features"> <article> <h3>대출</h3> <p>한 번에 다섯 권까지 빌립니다.</p> </article> <article> <h3>열람실</h3> <p>자리를 미리 예약합니다.</p> </article> <article> <h3>행사</h3> <p>매달 독서 모임이 열립니다.</p> </article> </div> </section> <section class="tint" id="join"> <div class="wrap narrow"> <h2>문의하기</h2> <form> <label for="nm">이름</label> <input id="nm" name="nm" required> <label for="msg">남길 말</label> <textarea id="msg" name="msg" rows="3"></textarea> <button class="btn">보내기</button> </form> </div> </section> <footer class="foot"> <div class="wrap"><p>문의 홍길동</p></div> </footer>
* { box-sizing: border-box; }
:root {
--brand: #6e56cf;
--ink: #3b4252;
--line: #e5e0f5;
--tint: #f8f7fd;
}
body {
font-family: "Pretendard", "맑은 고딕", sans-serif;
line-height: 1.7; color: var(--ink); margin: 0;
}
/* 구역마다 되풀이되는 폭 제한을 한 클래스로 둡니다 */
.wrap { max-width: 760px; margin: 0 auto; padding: 28px 16px; }
.narrow { max-width: 460px; }
/* 머리 줄 */
.bar { border-bottom: 1px solid var(--line); }
.bar-in {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 14px; padding-bottom: 14px;
}
/* 머리 화면 — 바탕은 끝까지, 글은 가운데로 */
.hero { background: var(--tint); text-align: center; }
.hero h1 { font-size: clamp(22px, 5vw, 34px); margin: 0 0 8px; }
.hero p { margin: 0 0 18px; color: #5b6272; }
/* 기능 목록 */
.features {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
gap: 14px;
}
.features article {
border: 1px solid var(--line);
border-radius: 10px;
padding: 16px;
}
.features h3 { margin: 0 0 4px; font-size: 1rem; color: var(--brand); }
.features p { margin: 0; color: #5b6272; font-size: 0.95rem; }
/* 문의 구역 */
.tint { background: var(--tint); }
form label { display: block; margin: 10px 0 4px; font-size: 0.9rem; }
input, textarea {
width: 100%; font: inherit;
padding: 9px 10px;
border: 1px solid #ccc; border-radius: 8px;
}
input:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
/* 단추 — a 와 button 에 같은 모양을 줍니다 */
.btn {
display: inline-block; font: inherit;
background: var(--brand); color: #fff;
border: 0; border-radius: 8px;
padding: 10px 20px; margin-top: 14px;
text-decoration: none; cursor: pointer;
transition: transform 0.15s ease;
}
.btn:hover, .btn:focus-visible { transform: translateY(-2px); }
.foot { border-top: 1px solid var(--line); color: #686c78; font-size: 0.9rem; }
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } }
상세 사용법
바탕은 끝까지, 글은 가운데로
이 화면의 핵심 짜임입니다. 구역(section)이 바탕색을
맡고, 그 안의 .wrap 이 폭을 맡습니다.
한 요소가 둘 다 맡으면
<section class="hero">…</section> .hero { max-width: 760px; background: #f8f7fd; } /* 바탕색도 760px 에서 끊깁니다 */
둘로 나누면
<section class="hero"> <div class="wrap">…</div> </section> .hero { background: #f8f7fd; } .wrap { max-width: 760px; margin: 0 auto; }
.wrap 을 한 번만 정의해 모든 구역이 씁니다. 폭을
바꿀 일이 생기면 한 줄만 고칩니다. 6.1 에서는 구역이 하나라 이렇게 나눌 까닭이
없었습니다.
상세 사용법
a 와 button 을 같은 모양으로
머리 화면의 "문의하기" 는 다른 자리로 가는 것이라
a 이고, 폼의 "보내기" 는 일을 하는 것이라
button 입니다. 보이는 모양은 같습니다.
| 붙일 것 | 까닭 |
|---|---|
display: inline-block | a 는 inline 이라 위아래 여백이 듣지 않습니다(2.9). |
font: inherit | button 이 글꼴을 물려받지 않습니다(5.2). |
text-decoration: none | a 의 밑줄을 없앱니다. |
cursor: pointer | button 은 기본이 화살표입니다. |
보이는 모양으로 태그를 고르지 마십시오. 가는 것이면
a, 하는 것이면 button
입니다. 키보드 조작과 화면 읽기 프로그램이 그 차이를 봅니다(5.1).
흔한 실수
세 가지
-
구역마다 폭 제한을 따로 적습니다. 값이 조금씩 달라져 구역끼리 어긋납니다.
.wrap하나로 두십시오. - 바탕색을 폭 제한한 요소에 줍니다. 색이 화면 끝까지 가지 않습니다.
-
단추를
div로 만듭니다. 모양은 같아도 키보드로 갈 수 없습니다(5.1).
실습 문제
직접 해보기
1. 구역을 하나 더 넣기
난이도 중
기능 목록과 문의 사이에 이용 시간 구역을 넣으십시오. 표로 요일과 시간을 담고, 바탕색은 흰색으로 둡니다.
바탕이 흰색이면
section 에 클래스를 줄 것 없이 .wrap 만 쓰면 됩니다. 표는 2.7 을 보십시오.<section class="wrap">
<h2>이용 시간</h2>
<table>
<tr><th>요일</th><th>시간</th></tr>
<tr><td>평일</td><td>09:00 ~ 18:00</td></tr>
<tr><td>주말</td><td>쉽니다</td></tr>
</table>
</section>
/* CSS */
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }
th { background: var(--tint); }
요약
정리
- 구역이 바탕색을, 안쪽
.wrap이 폭을 맡습니다. - 폭 제한은 클래스 하나로 두고 모든 구역이 함께 씁니다.
- 가는 것은
a, 하는 것은button입니다. - 둘에 같은 모양을 주려면
inline-block과font: inherit가 필요합니다.