HTML 레퍼런스 북

레이아웃04

4번 레이아웃은 전체 영역이 들어간 구조 실 사이트에서 이런 구조를 많이 사용하고 있으며,
컨테이너를 만들어서 가운데 영역을 설정한다.

float을 이용한 레이아웃 배치

clear : both;는 float: left; 로 인한 height 가 0이 되는 버그를 잡기위해 쓰는 속성이다.

* {
    margin: 0;
    padding: 0;
}
body {
}
#header {
    height: 100px;
    background-color: #E0F2F1;
}
#nav {
    height: 300px;
    background-color: #80CBC4;
}
#section {
    height: 580px;
    background-color: #26A69A;
}
#footer {
    height: 100px;
    background-color: #00897B;
}
/* .header_container {
    width: 1200px;
    height: 100px;
    background-color: #B2DFDB;
    margin: 0 auto;
}
.nav_container {
    width: 1200px;
    height: 300px;
    background-color: #4DB6AC;
    margin: 0 auto;
}
.section_container {
    width: 1200px;
    height: 580px;
    background-color: #009688;
    margin: 0 auto;
}
.footer_container {
    width: 1200px;
    height: 100px;
    background-color: #00796B;
    margin: 0 auto;
} */

/* 위 스타일들을 하나로 묶음 */
.container {
    width: 1200px;
    height: inherit; /* 부모의 heigt 값을 따르는 속성 */
    margin: 0 auto;
    background-color: rgba(0,0,0,0.3);
}

@media (max-width: 1220px){
    .container{
        width: 96%;
    }
}
@media (max-width: 768px){
    .container{
        width: 100%;
    }
}

flex을 이용한 레이아웃 배치

* {
    margin: 0;
}

#wrap {
    width: 100%;
}

#header {
    height: 100px;
    background-color: #EEEBE9;
}

#header .header {
    width: 100%;
    height: 100px;
    background-color: #D5CCC9;
}

#nav {
    height: 100px;
    background-color: #B9AAA5;
}

#nav .nav {
    width: 100%;
    height: 100px;
    background-color: #9D8980;
}

#main {
    height: 780px;
    background-color: #886F65;
}

#main .left {}

#main .left .cont1 {
    width: 100%;
    height: 100px;
    background-color: #74574A;
}

#main .right {
    display: flex;
    flex-wrap: wrap;
}

#main .right .cont2 {
    width: 100%;
    height: 200px;
    background-color: #684D43;
}

#main .right .cont3 {
    width: 50%;
    height: 480px;
    background-color: #594139;
}

#main .right .cont4 {
    width: 50%;
    height: 480px;
    background-color: #4A352F;
}

#footer {
    height: 100px;
    background-color: #4E342E;
}

#footer .footer {
    width: 100%;
    height: 100px;
    background-color: #3E2723;
}

.container {
    width: 1200px;
    height: inherit;
    margin: 0 auto;
}

@media (max-width: 1220px) {
    .container {
        width: 96%;
        display: flex;
        flex-wrap: wrap;

    }

    #main .left {
        width: 30%;
        height: 780px;

    }

    #main .left .cont1 {
        width: 100%;
        height: 780px;
    }

    #main .right {
        width: 70%;
        height: 780px;
    }

    #main .right .cont2 {
        width: 100%;
        height: 390px;
    }

    #main .right .cont3 {
        width: 50%;
        height: 390px;
    }

    #main .right .cont4 {
        width: 50%;
        height: 390px;
    }
}

@media (max-width: 768px) {
    .container {
        width: 100%;
    }

    #main .left {
        width: 30%;
        height: 780px;

    }

    #main .left .cont1 {
        width: 100%;
        height: 780px;
    }

    #main .right {
        width: 70%;
        height: 780px;
    }

    #main .right .cont2 {
        width: 100%;
        height: 260px;
    }

    #main .right .cont3 {
        width: 100%;
        height: 260px;
    }

    #main .right .cont4 {
        width: 100%;
        height: 260px;
    }
}


@media (max-width: 480px) {

    #main .left {
        width: 100%;
        height: 150px;

    }

    #main .left .cont1 {
        width: 100%;
        height: 780px;
    }

    #main .right {
        width: 100%;
        height: 630px;
        display: flex;
        flex-wrap: wrap;
    }

    #main .right .cont2 {
        width: 100%;
        height: 210px;
    }

    #main .right .cont3 {
        width: 100%;
        height: 210px;
    }

    #main .right .cont4 {
        width: 100%;
        height: 210px;
    }
}

grid을 이용한 레이아웃 배치 (반응형 포함)

* {
    margin: 0;
}

#wrap {
    width: 100%;
}

#header {
    height: 100px;
    background-color: #EEEBE9;
}

#header .header {
    width: 100%;
    background-color: #D5CCC9;
}

#nav {
    height: 100px;
    background-color: #B9AAA5;
}

#nav .nav {
    width: 100%;
    background-color: #9D8980;
}

#main {
    height: 780px;
    background-color: #886F65;
}

.contants {
    display: grid;
    grid-template-areas:
        "cont1 cont1"
        "cont2 cont2"
        "cont3 cont4";
    grid-template-columns: 50%px 50%px;
    grid-template-rows: 100px 200px 480px;
}

.contants .cont1 {
    background-color: #74574A;
    grid-area: cont1;
}

.contants .cont2 {
    background-color: #684D43;
    grid-area: cont2;
}

.contants .cont3 {
    background-color: #594139;
    grid-area: cont3;
}

.contants .cont4 {
    background-color: #4A352F;
    grid-area: cont4;
}

#footer {
    height: 100px;
    background-color: #4E342E;
}

#footer .footer {
    width: 100%;
    background-color: #3E2723;
}

.container {
    width: 1200px;
    height: inherit;
    margin: 0 auto;
    background-color: rgba(0, 0, 0, 0.3);
}

@media (max-width: 1220px) {
    .container {
        width: 96%;
    }

    .contants {
        display: grid;
        grid-template-areas:
            "cont1 cont2 cont2"
            "cont1 cont3 cont4";
        grid-template-columns: 30% 35% 35%;
        grid-template-rows: 390px 390px;
    }
}

@media (max-width: 768px) {
    .container {
        width: 100%;
    }

    .contants {
        display: grid;
        grid-template-areas:
            "cont1 cont2"
            "cont1 cont3"
            "cont1 cont4";
        grid-template-columns: 40% 60%;
        grid-template-rows: 260px 260px 260px;
    }
}


@media (max-width: 480px) {
    .contants {
        display: grid;
        grid-template-areas:
            "cont1"
            "cont2"
            "cont3"
            "cont4";
        grid-template-columns: 100%;
        grid-template-rows: px 150px 210px 210px 210px;
    }
}