HTML 레퍼런스 북

레이아웃02

사이드가 2개인 구조

float을 이용한 레이아웃 배치

* {
    margin: 0;
    padding: 0;
}
#wrap {
    width: 1200px;
    margin: 0 auto;
}
#header {
    width: 1200px;
    height: 100px;
    background-color: #C8E6C9;
}
#nav {
    width: 1200px;
    height: 100px;
    background-color: #A5D6A7;
}
#aside {
    width: 300px;
    height: 780px;
    background-color: #81C784;
    float: left;
}
#section {
    width: 600px;
    height: 780px;
    background-color: #66BB6A;
    float: left;  
}
#aside2 {
    width: 300px;
    height: 780px;
    background-color: #4CAF50;
    float: left;
}
#footer {
    width: 1200px;
    height: 100px;
    background-color: #43A047;
    clear: both;
}
}

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

* {
    margin: 0;
    padding: 0;
}
#wrap {
    width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
}
#header {
    width: 100%;
    height: 100px;
    background-color: #C8E6C9;
}
#nav {
    width: 100%;
    height: 100px;
    background-color: #A5D6A7;
}
#aside {
    width: 20%;
    height: 780px;
    background-color: #81C784;
}
#section {
    width: 60%;
    height: 780px;
    background-color: #66BB6A;
}
#aside2 {
    width: 20%;
    height: 780px;
    background-color: #4CAF50;
}
#footer {
    width: 100%;
    height: 100px;
    background-color: #43A047;
}

@media (max-width:1300px){
    #wrap {
        width: 96%;
    }
}
@media (max-width:768px){
    #wrap {
        width: 100%;
    }
    #aside {
    width: 40%;
    height: 630px;
    background-color: #81C784;
    }
    #section {
    width: 60%;
    height: 630px;
    background-color: #66BB6A; 
    }
    #aside2 {
    width: 100%;
    height: 150px;
    background-color: #4CAF50;
    }
}
@media (max-width:480px){
    #aside {
    width: 100%;
    height: 200px;
    background-color: #81C784;
    }
    #section {
    width: 100%;
    height: 430px;
    background-color: #66BB6A; 
    }
}

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

* {
    margin: 0;
    padding: 0;
}
#wrap {
    width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-areas: 
    "header header header"
    "nav nav nav"
    "aside section aside2"
    "footer footer footer"
    ;
    grid-template-columns: 20% 60% 20%;
    grid-template-rows: 100px 100px 780px 100px;
}
#header {
    background-color: #C8E6C9;
    grid-area: header;
}
#nav {
    background-color: #A5D6A7;
    grid-area: nav;
}
#aside {
    background-color: #81C784;
    grid-area: aside;
}
#section {
    background-color: #66BB6A;
    grid-area: section;
}
#aside2 {
    background-color: #4CAF50;
    grid-area: aside2;
}
#footer {
    background-color: #43A047;
    grid-area: footer;
}

@media (max-width:1300px){
    #wrap {
        width: 96%;
    }
}
@media (max-width:768px){
    #wrap {
        width: 100%;
        grid-template-areas: 
        "header header"
        "nav nav"
        "aside section"
        "aside2 aside2"
        "footer footer"
        ;
        grid-template-columns: 40% 60%;
        grid-template-rows: 100px 100px 630px 150px 100px;
    }
}
@media (max-width:480px){
    #wrap {
        width: 100%;
        grid-template-areas: 
        "header"
        "nav"
        "aside"
        "section"
        "aside2"
        "footer"
        ;
        grid-template-columns: 100%;
        grid-template-rows: 100px 100px 200px 430px 150px 100px;
    }
}


결과 값