728x90
반응형
레이아웃03
이번 레이아웃은 전체 영역이 들어간 구조입니다. 실제 사이트에서 이런 구조를 많이 사용하며, 컨테이너를 만들어서 가운데 영역을 설정합니다.
float을 이용한 레이아웃
float 속성을 설정한 뒤 overflow: hidden; 를 설정하면 벗아나는 부분이 보이지 않는 단점이 있으므로 부모 영역을 설정한 후, 그 곳에다가 'clearfix'를 설정해 줄 수 있습니다. before와 after를 설정 해준 뒤 content: ''; 설정으로 가상의 요소를 줍니다. display: block; 으로 블럭화를 시킨 후, line-height: 0;을 설정(공간을 차지하기 때문에 설정 해 줍니다.) 해줍니다. 마지막으로 after의 부분에 clear: both;를 설정해주면 됩니다.
* {
margin: 0;
padding: 0;
}
body {
background-color: #E1F5FE;
}
#wrap {
width: 1200px;
margin: 0 auto;
}
#header {
width: 1200px;
height: 100px;
background-color: #B3E5FC;
}
#nav {
width: 1200px;
height: 100px;
background-color: #81D4FA;
}
#main {
width: 1200px;
/* overflow: hidden; 벗어나는 부분이 보이지 않는 단점이 있음 */
}
#aside {
width: 300px;
height: 780px;
background-color: #4FC3F7;
float: left;
}
#article1 {
width: 900px;
height: 260px;
background-color: #29B6F6;
float: left;
}
#article2 {
width: 900px;
height: 260px;
background-color: #03A9F4;
float: left;
}
#article3 {
width: 900px;
height: 260px;
background-color: #039BE5;
float: left;
}
#footer {
width: 1200px;
height: 100px;
background-color: #0288D1;
/* clear: both; 구조가 복잡해지면 어디에 쓰는지 알 수 없음 */
}
/* clearfix - 가장 안정적인 방법 */
.clearflx::before,
.clearflx::after {
content: ''; /* 가상으로 요소를 줄 수 있음 */
display: block; /* 블럭화 시키기 */
line-height: 0; /* 공간을 차지 하기 때문에 */
}
.clearflx::after {
clear: both;
} /* float 쓸때 영역이 깨지면 사용 가능함 */
결과
flex을 이용한 레이아웃
* {
margin: 0;
padding: 0;
}
body {
background-color: #E1F5FE;
}
#wrap {
width: 1200px;
margin: 0 auto;
}
#header {
height: 100px;
background-color: #B3E5FC;
}
#nav {
height: 100px;
background-color: #81D4FA;
}
#main {
display: flex;
flex-wrap: wrap; /* 크기를 맞춰주는 것 */
flex-direction: column; /* flex 방향설정 */
height: 780px; /* height 값 고정해주면 그 안에서 맞춤 */
}
#aside {
width: 30%;
height: 780px;
background-color: #4FC3F7;
}
#article1 {
width: 70%;
height: 260px;
background-color: #29B6F6;
}
#article2 {
width: 70%;
height: 260px;
background-color: #03A9F4;
}
#article3 {
width: 70%;
height: 260px;
background-color: #039BE5;
}
#footer {
height: 100px;
background-color: #0288D1;
}
결과
grid룰 이용한 레이아웃
* {
margin: 0;
padding: 0;
}
body {
background-color: #E1F5FE;
}
#wrap {
width: 1200px;
margin: 0 auto;
}
#header {
height: 100px;
background-color: #B3E5FC;
}
#nav {
height: 100px;
background-color: #81D4FA;
}
#main {
display: grid;
grid-template-areas:
"aside article1 article1"
"aside article2 article2"
"aside article3 article3"
;
grid-template-columns: 300px 900px;
grid-template-rows: 260px 260px 260px;
}
#aside {
grid-area: aside;
background-color: #4FC3F7;
}
#article1 {
grid-area: article1;
background-color: #29B6F6;
}
#article2 {
grid-area: article2;
background-color: #03A9F4;
}
#article3 {
grid-area: article3;
background-color: #039BE5;
}
#footer {
height: 100px;
background-color: #0288D1;
}
댓글