반응형
레이아웃05
이번 레이아웃은 반응형 적용을 위해 메인-좌,우 영역이 나누어진 레이아웃입니다.
float : clearfix를 이용한 레이아웃
부모 요소가 다시 자식 요소를 감쌀 수 있게 float을 초기화(clear)하여 버그를 고쳐주는(fix) 코드입니다.
* {
margin: 0;
}
#wrap {}
#header {
height: 100px;
background-color: #EEEBE9;
}
#nav {
height: 100px;
background-color: #B9AAA5;
}
#main {
height: 780px;
background-color: #886F65;
}
#footer {
height: 100px;
background-color: #4E342E;
}
.container {
width: 1200px;
margin: 0 auto;
height: inherit;
background-color: rgba(0, 0, 0, 0.3);
}
.contents {
overflow: hidden;
}
.contents .cont_left {
height: 100px;
}
.contents .cont1 {
height: 100px;
background-color: #74574A;
}
.contents .cont_right {}
.contents .cont2 {
height: 200px;
background-color: #684D43;
}
.contents .cont3 {
width: 50%;
height: 480px;
background-color: #594139;
float: left;
}
.contents .cont4 {
width: 50%;
height: 480px;
background-color: #4A352F;
float: left;
}
/*
float으로 인한 영역깨짐 방지법
1. 깨지는 영역에 clear: both를 설정한다. 깨지는부분이 눈에보이지 않으므로 좋지않은방법
2. 부모 박스 영역에 overflow: hidden을 설정한다.
3. clearfix를 설정한다. (가상요소)
*/
.clearfix::before,
.clearfix::after {
content: '';
display: block;
line-height: 0;
}
.clearfix::after {
clear: both;
}
flex을 이용한 레이아웃
* {
margin: 0;
}
#wrap {}
#header {
height: 100px;
background-color: #EEEBE9;
}
#nav {
height: 100px;
background-color: #B9AAA5;
}
#main {
height: 780px;
background-color: #886F65;
}
#footer {
height: 100px;
background-color: #4E342E;
}
.container {
width: 1200px;
margin: 0 auto;
height: inherit;
background-color: rgba(0, 0, 0, 0.3);
}
.contents {}
.contents .cont_left {}
.contents .cont1 {
height: 100px;
background-color: #74574A;
}
.contents .cont_right {
display: flex;
flex-wrap: wrap;
}
.contents .cont2 {
width: 100%;
height: 200px;
background-color: #684D43;
}
.contents .cont3 {
width: 50%;
height: 480px;
background-color: #594139;
}
.contents .cont4 {
width: 50%;
height: 480px;
background-color: #4A352F;
}
grid을 이용한 레이아웃 : 반응형 적용
repeat는 반복되는 값을 자동으로 처리할 수 있는 함수입니다.
fr은 fraction(뜻 : 여기로), 숫자 비율대로 트랙의 크기를 나눕니다.
* {
margin: 0;
}
#wrap {}
#header {
height: 100px;
background-color: #EEEBE9;
}
#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;
}
@media (max-width:1220px) {
.container {
width: 96%;
}
.contents {
display: grid;
grid-template-areas:
"cont1 cont2 cont2"
"cont1 cont3 cont4";
grid-template-columns: repeat(3, 1fr);
/*
repeat(3, 1fr);
repeat(3, 33.3333%);
1fr 1fr 1fr;
33.3333% 33.3333% 33.3333%;
*/
grid-template-rows: repeat(2, 1fr)
}
}
@media (max-width:768px) {
.container {
width: 100%;
}
.contents {
display: grid;
grid-template-areas:
"cont1 cont2"
"cont1 cont3"
"cont1 cont4";
grid-template-columns: 30% 70%;
grid-template-rows: repeat(3, 1fr)
}
}
@media (max-width:480px) {
.container {
width: 100%;
}
.contents {
display: grid;
grid-template-areas:
"cont1"
"cont2"
"cont3"
"cont4";
grid-template-columns: 100%;
grid-template-rows: 150px 210px 210px 210px;
}
}
반응형
댓글