HTML 레퍼런스 북

레이아웃05

전체 영역 레이아웃을 크게 잡고, 컨테이너로 세부적인 레이아웃을 또 잡는다.

float을 이용한 레이아웃 배치

* {
    margin: 0;
}
#wrap {
    width: 100%;
}
#header {
    height: 100px;
    background-color: #EEEBE9;
}
#header .header {
    width: 1200px;
    height: 100px;
    background-color: #D5CCC9;
}
#nav {
    height: 100px;
    background-color: #B9AAA5;
}
#nav .nav {
    width: 1200px;
    height: 100px;
    background-color: #9D8980;
}
#main {
    height: 780px;
    background-color: #886F65;
}
#main .cont1 {
    width: 100%;
    height: 100px;
    background-color: #74574A;
}
#main .cont2 {
    width: 100%;
    height: 200px;
    background-color: #684D43;
}
#main .cont3 {
    width: 50%;
    height: 480px;
    background-color: #594139;
    float: left;
}
#main .cont4 {
    width: 50%;
    height: 480px;
    background-color: #4A352F;
    float: left;
}
#footer {
    height: 100px;
    background-color: #4E342E;
}
#footer .footer {
    width: 100%;
    height: 100px;
    background-color: #3E2723;
}
.container {
    width: 1200px;
    height: inherit;
    margin: 0 auto;
    overflow: hidden;
}

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

    }
    #main .cont1 {
        width: 30%;
        height: 780px;
        float: left;
    }
    #main .cont2 {
        width: 70%;
        height: 390px;
        float: left;
    }
    #main .cont3 {
        width: 35%;
        height: 390px;
        float: left;
    }
    #main .cont4 {
        width: 35%;
        height: 390px;
        float: left;
    }
}
@media (max-width: 768px) {
    .container {
    width: 100%;
    }
    #main .cont1 {
        width: 30%;
        height: 780px;
        float: left;
    }
    #main .cont2 {
        width: 70%;
        height: 260px;
        float: left;
    }
    #main .cont3 {
        width: 70%;
        height: 260px;
        float: left;
    }
    #main .cont4 {
        width: 70%;
        height: 260px;
        float: left;
    }
}
@media (max-width: 480px) {
    #main .cont1 {
        width: 100%;
        height: 150px;
        float: left;
    }
    #main .cont2 {
        width: 100%;
        height: 210px;
        float: left;
    }
    #main .cont3 {
        width: 100%;
        height: 210px;
        float: left;
    }
    #main .cont4 {
        width: 100%;
        height: 210px;
        float: left;
    }
}

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;
    }
}


결과 값