웹 페이지의 레이아웃이란?
메뉴, 컨텐츠, 부가정보 등과 같은 구성요소들을 필요한 곳에 위치하여 사용자가 효과적으로 웹사이트를 이용할 수 있게 배치하는 작업
종류
1단 레이아웃은 위의 이미지와 같이 하나의 행(column)으로 이루어진 레이아웃의 형태를 일컫는다.
상단(header), 중단(contents), 하단(footer)의 구성으로 이루어져있는 것이 가장 일반적이다.
스타일 정보
컨텐츠 최대 가로 길이: 1200
사이트 최소 가로 길이: 800
컨텐츠 가운데 정렬
주요 태그 및 속성
<!-- 1단 레이아웃 -->
<div class="header">header</div>
<div class="content">content</div>
<div class="footer">footer</div>
<!-- 1단 레이아웃 -->
<!-- html5의 태그를 이용한 1단 레이아웃 -->
<header>header</header>
<section>content</section>
<footer>footer</footer>
<!-- div를 이용한 1단 레이아웃 -->
<div class="wrap">
<div class="header">header</div>
<div class="content">content</div>
<div class="footer">footer</div>
</div>
<!-- html5를 이용한 1단 레이아웃 -->
<div class="wrap">
<header>header</header>
<section>content</section>
<footer>footer</footer>
</div>
.header{
height: 100px;
background-color: lightgreen;
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
height:100px;
background-color: lightblue;
}
.header{
height: 100px;
background-color: lightgreen;
}
.content{
max-width: 1200px; /* 최대 가로길이 1200px */
height: 300px;
margin: 0 auto; /* 블럭요소 가운데 정렬 */
background-color: lightsalmon;
}
.footer{
height:100px;
background-color: lightblue;
}
.wrap {
min-width: 800px; /* 최소 가로길이 800px */
}
.header{
height: 100px;
background-color: lightgreen;
}
.content{
max-width: 1200px;
height: 300px;
margin: 0 auto;
background-color: lightsalmon;
}
.footer{
height:100px;
background-color: lightblue;
}
1단 레이아웃과 같이 각 항목을 생성한다. 2단 메뉴에서는 사이드영역이 추가되므로 aside라는 클래스명을 추가한다.
또한 행(coulmn)을 나누게 될 영역들을 container라는 클래스명을 가진 div로 묶는다.
<div class="wrap">
<div class="header">header</div>
<div class="container"> <!-- content와 aside의 묶음 영역 추가 -->
<div class="content">content</div>
<div class="aside">aside</div>
</div>
<div class="footer">footer</div>
</div>
</div>
.header {
height:100px;
background-color: lightgreen;
}
.container {
width: 800px;
margin: 0 auto;
}
.content {
height: 300px;
background-color: lightsalmon;
}
.aside {
height: 300px;
background-color: lightseagreen;
}
.footer {
height:100px;
background-color: cornflowerblue;
}
.header {
height:100px;
background-color: lightgreen;
}
.container {
width: 800px;
margin: 0 auto;
}
.content {
float: left; /* float */
width: 500px; /* 가로사이즈 추가 */
height: 300px;
background-color: lightsalmon;
}
.aside {
float: left; /* float */
width: 300px; /* 가로사이즈 추가 */
height: 300px;
background-color: lightseagreen;
}
.footer {
height:100px;
background-color: cornflowerblue;
}
.header {
height:100px;
background-color: lightgreen;
}
.container {
width: 800px;
margin: 0 auto;
}
.container:after { /* after를 이용하여 float해제하기 */
display: block;
clear: both;
content: '';
}
.content {
float: left;
width: 500px;
height: 300px;
background-color: lightsalmon;
}
.aside {
float: left;
width: 300px;
height: 300px;
background-color: lightseagreen;
}
.footer {
height:100px;
background-color: cornflowerblue;
}
.header {
height:100px;
background-color: lightgreen;
}
.container {
position: relative; /* position 기준영역 설정 */
width: 800px;
margin: 0 auto;
}
.container:after {
display: block;
clear: both;
content: '';
}
.content {
float: left;
width: 500px;
height: 300px;
background-color: lightsalmon;
}
.aside {
float: left;
width: 300px;
height: 300px;
background-color: lightseagreen;
}
.aside:after{ /* 구분선 만들기 */
content:'';
position:absolute;
right:300px;
top: 0;
bottom: 0;
width:5px;
background-color: #000;
}
.footer {
height:100px;
background-color: cornflowerblue;
}
.header {
height:100px;
background-color: lightgreen;
}
.container {
width: 800px;
margin: 0 auto;
}
.content {
height: 300px;
background-color: lightsalmon;
}
.aside {
height: 300px;
background-color: lightseagreen;
}
.footer {
height:100px;
background-color: cornflowerblue;
}
.header {
height:100px;
background-color: lightgreen;
}
.container {
display: table; /* 부모 요소에 display: table 추가 */
width: 800px;
margin: 0 auto;
}
.content {
display: table-cell; /* 자식 요소에 display: table-cell 추가 */
width: 500px; /* 가로 사이즈 부여 ( aside가로길이 = container 가로길이 - content 가로길이) */
height: 300px;
background-color: lightsalmon;
}
.aside {
display: table-cell;/* 자식 요소에 display: table-cell 추가 */
height: 300px;
background-color: lightseagreen;
}
.footer {
height:100px;
background-color: cornflowerblue;
}
.header {
height:100px;
background-color: lightgreen;
}
.container {
display: table;
width: 800px;
margin: 0 auto;
}
.content {
display: table-cell;
width: 495px; /* -5px 하여 추가된 구분선 만큼 빼기 */
height: 300px;
background-color: lightsalmon;
border-right: 5px solid #000; /* border를 이용해 구분선 추가 */
}
.aside {
display: table-cell;
height: 300px;
background-color: lightseagreen;
}
.footer {
height:100px;
background-color: cornflowerblue;
}
주요 기능
header 영역과 footer 영역이 상하단에 고정노출
컨텐츠의 최소높이값이 100%인 레이아웃형태 만들기
스타일 정보
header 상단 고정
footer 하단 고정
콘텐츠 최소 높이값 100%
주요 태그 및 속성
HTML
div
CSS
position: fixed
min-height
margin
padding
<div class="wrap">
<div class="header">header</div>
<div class="container">
<div class="content">content</div>
</div>
<div class="footer">footer</div>
</div>
.header{
height: 100px;
background-color: lightgreen;
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
height:100px;
background-color: lightblue;
}
.header{
position: fixed; /* position 고정 */
top: 0; left: 0; right: 0; /* 상단 위치 */
height: 100px;
background-color: lightgreen;
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
height:100px;
background-color: lightblue;
}
.header {
position: fixed;
top: 0; left: 0; right: 0;
height: 100px;
background-color: lightgreen;
}
.container {
min-height: 100%; /* 최소 높이값 100% */
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
position: fixed;
bottom: 0; left: 0; right: 0;
height:100px;
background-color: lightblue;
}
html,
body,
.wrap {
height: 100%;
}
html,
body,
.wrap {
height: 100%;
}
.header {
position: fixed;
top: 0; left: 0; right: 0;
height: 100px;
background-color: lightgreen;
}
.container {
min-height: 100%;
margin-top: -100px; /* 음수 마진으로 푸터의 높이만큼 끌어올려주기 */
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
position: fixed;
bottom: 0; left: 0; right: 0;
height:100px;
background-color: lightblue;
}
html,
body,
.wrap {
height: 100%;
}
.header {
position: fixed;
top: 0; left: 0; right: 0;
height: 100px;
background-color: lightgreen;
}
.container {
min-height: 100%;
margin-top: -100px;
}
.content{
height: 300px;
padding-top: 200px; /* 가려진 height의 높이값과 끌어올린 footer의 높이값을 합친 값을 padding-top으로 밀어줍니다. */
background-color: lightsalmon;
}
.footer{
position: fixed;
bottom: 0; left: 0; right: 0;
height:100px;
background-color: lightblue;
}
box-sizing
을 이용하여 상단을 고정하는 방법html,
body,
.wrap {
height: 100%;
}
.header {
position: fixed;
top: 0; left: 0; right: 0;
height: 100px;
background-color: lightgreen;
}
.container {
min-height: 100%;
margin-top: -100px;
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
position: fixed;
bottom: 0; left: 0; right: 0;
height:100px;
background-color: lightblue;
}
html,
body,
.wrap {
height: 100%;
}
.header {
position: fixed;
top: 0; left: 0; right: 0;
height: 100px;
background-color: lightgreen;
}
.container {
min-height: 100%;
margin-top: -100px;
padding-top: 200px; /* 가려진 header와 끌어올린 footer의 높이값 만큼 부여 */
box-sizing: border-box; /* padding이나 border를 컨텐츠에 부여된 높이값에 포함 */
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
position: fixed;
bottom: 0; left: 0; right: 0;
height:100px;
background-color: lightblue;
}
.header{
position: fixed; /* position 고정 */
top: 0; left: 0; right: 0; /* 상단 위치 */
height: 100px;
background-color: lightgreen;
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
position: fixed; /* position 고정 */
bottom: 0; left: 0; right: 0; /* 하단 위치 */
height:100px;
background-color: lightblue;
}
html,
body,
.wrap {
height: 100%; /* 부모요소에 height 100% 부여 */
}
.header{
position: fixed;
top: 0; left: 0; right: 0;
height: 100px;
background-color: lightgreen;
}
.container {
min-height: 100%; /* 최소높이값 100% 설정 */
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
position: fixed;
bottom: 0; left: 0; right: 0;
height:100px;
background-color: lightblue;
}
html,
body,
.wrap {
height: 100%; /* 부모요소에 height 100% 부여 */
}
.header{
position: fixed;
top: 0; left: 0; right: 0;
height: 100px;
background-color: lightgreen;
}
.container {
min-height: 100%;
padding: 100px 0; /* height, footer 뒤로 가려진 영역 노출 */
box-sizing: border-box; /* padding값을 높이에서 무시하도록 속성 추가 */
}
.content{
height: 300px;
background-color: lightsalmon;
}
.footer{
position: fixed;
bottom: 0; left: 0; right: 0;
height:100px;
background-color: lightblue;
}