레이아웃05
float을 이용한 레이아웃
float을 사용한 후 영역이 깨지는 것을 방지하기 위해서는 세 가지의 방법이 있습니다.
첫번째는 깨지는 영역에 clear:both를 설정합니다. 하지만, 구조가 복잡해지면 쓰기 힘들어 지는 단점이 있습니다.
두번짼는 부모 박스 영역에 overflow:hidden을 설정합니다. 그러나, 이 경우에는 애니메이션 등이 보이지 않는 경우가 생기기도 합니다.
마지막 방법으로는 clearfix를 설정하는 것 입니다.
/* clearfix */
.clearfix::before,
.clearfix::after {
content: '';
display: block;
line-height: 0;
}
.clearfix::after {
clear: both;
}
* {
margin: 0;
}
#wrap {
width: 100%;
}
#header {
width: 100%;
height: 100px;
background-color: #EEEBE9;
}
#banner {
width: 100%;
height: 100px;
background-color: #B9AAA5;
}
#main {
width: 100%;
height: 780px;
background-color: #886F65;
}
#footer {
width: 100%;
height: 100px;
background-color: #4E342E;
}
.container {
width: 1200px;
height: inherit;
background-color: rgba(0,0,0,0.3);
margin: 0 auto;
}
#header .container {
height: 100px;
background-color: #D5CCC9;
}
#banner .container {
height: 100px;
background-color: #9D8980;
}
#main .main_box1 {
width: 100%;
height: 100px;
background-color: #74574A;
}
#main .main_box2 {
width: 100%;
height: 200px;
background-color: #684D43;
}
#main .main_box3 {
width: 50%;
height: 480px;
background-color: #594139;
float: left;
}
#main .main_box4 {
width: 50%;
height: 480px;
background-color: #4A352F;
float: left;
}
#footer .footerbox {
width: 100%;
height: 100px;
background-color: #3E2723;
}
/* clearfix */
.clearfix::before,
.clearfix::after {
content: '';
display: block;
line-height: 0;
}
.clearfix::after {
clear: both;
}
결과
flex를 이용한 레이아웃
레이아웃 유형 05번째에서 flex를 사용할 경우, 미디어 반응에서 flex가 아래와 같이 반응하지 않는 현상이 발생 할 수 있습니다.

이럴경우 main컨텐츠를 미디어 반응까지 고려하여 분활 시킵니다.
<main id="main">
<section class="contents container">
<article class="left">
<article class="cont1"></article>
</article>
<article class="right">
<article class="cont2"></article>
<article class="cont3"></article>
<article class="cont4"></article>
</article>
</section>
</main>
* {
margin: 0;
padding: 0;
}
#wrap {
width: 100%;
}
#header {
width: 100%;
height: 100px;
background-color: #EEEBE9;
}
#nav {
width: 100%;
height: 100px;
background-color: #B9AAA5;
}
#main {
width: 100%;
height: 780px;
background-color: #886F65;
}
#footer {
width: 100%;
height: 100px;
background-color: #4E342E;
}
.container {
width: 1200px;
height: inherit;
margin: 0 auto;
background-color: rgba(0,0,0,0.3);
}
.contents .right {
display: flex;
flex-wrap: wrap;
}
.contents .left .cont1 {
width: 100%;
height: 100px;
background-color: #74574A;
}
.contents .right .cont2 {
width: 100%;
height: 200px;
background-color: #684D43;
}
.contents .right .cont3 {
width: 50%;
height: 480px;
background-color: #594139;
}
.contents .right .cont4 {
width: 50%;
height: 480px;
background-color: #4A352F;
}
결과
grid를 이용한 레이아웃
grid의 경우 부모 컨텐츠에 설정을 해준 다음, 각각의 grid-area를 설정하면 간단하게 레이아웃을 구성할 수 있습니다.

* {
margin: 0;
padding: 0;
}
#wrap {}
#header {
height: 100px;
background-color: #fff;
}
#nav {
height: 100px;
background-color: #B9AAA5;
}
#main {
height: 780px;
background-color: #886F65;
}
#footer {
height: 100px;
background-color: #4E342E;
}
.container {
width: 1200px;
height: inherit;
margin: 0 auto;
background-color: rgba(0,0,0,0.3);
}
.contents {
display: grid;
grid-template-areas:
"cont1 cont1"
"cont2 cont2"
"cont3 cont4"
;
grid-template-columns: 50% 50%;
grid-template-rows: 100px 200px 480px;
}
.contents .cont1 {
background-color: #74574A;
grid-area: cont1;
}
.contents .cont2 {
background-color: #684D43;
grid-area: cont2;
}
.contents .cont3 {
background-color: #594139;
grid-area: cont3;
}
.contents .cont4 {
background-color: #4A352F;
grid-area: cont4;
}
댓글