๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ ˆ์ด์•„์›ƒ

๋ ˆ์ด์•„์›ƒ 05

by Youcodein 2022. 7. 29.
728x90
๋ฐ˜์‘ํ˜•

๋ ˆ์ด์•„์›ƒ3

์ด๋ฒˆ ๋ ˆ์ด์•„์›ƒ์€ section์ด 4๊ฐœ๋กœ ๋‚˜๋ˆ„์–ด์ง„ ๋ ˆ์ด์•„์›ƒ์ž…๋‹ˆ๋‹ค.

float์„ ์ด์šฉํ•œ ๋ ˆ์ด์•„์›ƒ

<div>ํƒœ๊ทธ๋ฅผ float ์†์„ฑ ๋ฐ widh, height์†์„ฑ ๋“ฑ์„ ์ด์šฉํ•˜์—ฌ ๋ ˆ์ด์•„์›ƒ์„ ๋ฐฐ์น˜ํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

/* 
float์œผ๋กœ ์ธํ•œ ์˜์—ญ๊นจ์ง ๋ฐฉ์ง€๋ฒ•
1. ๊นจ์ง€๋Š” ์˜์—ญ์— clear:both๋ฅผ ์„ค์ •ํ•œ๋‹ค.
2. ๋ถ€๋ชจ ๋ฐ•์Šค ์˜์—ญ์— overflow: hidden์„ ์„ค์ •ํ•œ๋‹ค.
3. clearfix๋ฅผ ์„ค์ •ํ•œ๋‹ค.
    */

.clearfix::before,
.clearfix::after{
    content: '';
    display: block;
    line-height: 0;
}
.clearfix::after{
    clear: both;
}

*{
    margin: 0;
    padding: 0;
}
#wrap {
    width: 100%;
}
#header {
    width: 100%;
    height: 100px;
    background-color: #EEEBE9;
}
#nav {
    width: 100%;
    height: 100px;
    background-color: #B9AAA5;
}
#main {
    width: 100%;
    height: 780px;
    background-color: #886F65;
}
#footer {
    width: 100%;
    height: 100px;
    background-color: #4E342E;
}
.container {
    width: 1200px;
    height: inherit;
    background-color: rgba(0,0,0,0.3);
    overflow: hidden;
    margin: 0 auto;
}
.header {
    width: 1200px;
    height: 100px;
    background-color: #D5CCC9;
}
.nav {
    width: 1200px;
    height: 100px;
    background-color: #9D8980;
}
.contents .cont1 {
    width: 100%;
    height: 100px;
    background-color: #74574A;
}
.contents .cont2 {
    width: 100%;
    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;
}
.contents .footer {
    width: 1200px;
    height: 100px;
    background-color: #3E2723;
}

@media(max-width: 1220px){
    .container {
        width: 96%;
    }
    .contents .cont1 {
        width: 30%;
        height: 780px;
        float: left;
    }
    .contents .cont2 {
        width: 70%;
        height: 390px;
        float: left;
    }
    .contents .cont3 {
        width: 35%;
        height: 390px;
    }
    .contents .cont4 {
        width: 35%;
        height: 390px;
    }
}
@media(max-width: 768px){
    .container {
        width: 100%;
    }


    .contents .cont1 {
        width: 30%;
        height: 780px;
    }
    .contents .cont2 {
        width: 70%;
        height: 260px;
    }
    .contents .cont3 {
        width: 70%;
        height: 260px;
    }
    .contents .cont4 {
        width: 70%;
        height: 260px;
    }
}
@media(max-width: 480px){

    .contents .cont1 {
        width: 100%;
        height: 150px;
    }
    .contents .cont2 {
        width: 100%;
        height: 210px;
    }
    .contents .cont3 {
        width: 100%;
        height: 210px;
    }
    .contents .cont4 {
        width: 100%;
        height: 210px;
    }
}

flex์„ ์ด์šฉํ•œ ๋ ˆ์ด์•„์›ƒ

header์™€ footer๋ฅผ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ์š”์†Œ๋“ค์„ container ํด๋ž˜์Šค๋กœ ๋ฌถ๊ณ  container์•ˆ์˜ ์š”์†Œ๋“ค์„ ๋ฐฐ์น˜ํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

* {
    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;
    height: 780px;
}
#aside {
    width: 30%;
    height: 780px;
    background-color: #4FC3F7;
    float: left;
}
#article1 {
    width: 70%;
    height: 260px;
    background-color: #29B6F6;
    float: left;
}
#article2-1 {
    width: 100%;
    height: 260px;
    background-color: #03A9F4;
    float: left;
}
#article2-2 {
    width: 100%;
    height: 260px;
    background-color: #039BE5;
    float: left;
}
#footer {
    height: 100px;
    background-color: #0288D1;
}

@media (max-width: 1300px){
    #wrap {
        width: 96%;
    }
    #article2 {
        display: flex;
    }
    #article2-1 {
        width: 50%;
        height: 520px;
    }
    #article2-2 {
        width: 50%;
        height: 520px;
    }
}

@media (max-width: 768px){
    #wrap {
        width: 100%;
    }
    #article1 {
        width: 100%;
        height: 390px;
    }
    #article2-1 {
        width: 100%;
        height: 390px;
    }
    #article2-2 {
        display: none;
        
    }
}

@media (max-width: 480px){
    #aside {
        width: 100%;
        height: 200px;
    }
    #article1 {
        height: 430px;
    }
    #article2-1 {
        height: 150px;
    }
}

grid๋ฅผ ์ด์šฉํ•œ ๋ ˆ์ด์•„์›ƒ

grid ๋ ˆ์ด์•„์›ƒ์€ 1์ฐจ์› ์‹œ์Šคํ…œ์ธ ํ”Œ๋ ‰์Šค ๋ฐ•์Šค์™€๋Š” ๋‹ค๋ฅด๊ฒŒ ์—ด๊ณผ ํ–‰ ๋ชจ๋‘ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๋Š” 2์ฐจ์› ์‹œ์Šคํ…œ์ด๋ฉฐ, CSS ๊ทœ์น™์— ๋”ฐ๋ผ ๋ถ€๋ชจ ์š”์†Œ(๊ทธ๋ฆฌ๋“œ ์ปจํ…Œ์ด๋„ˆ)์™€ ์ž์‹ ์š”์†Œ(๊ทธ๋ฆฌ๋“œ ์•„์ดํ…œ)๋กœ ๊ทธ๋ฆฌ๋“œ ๋ ˆ์ด์•„์›ƒ ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค.

* {
    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: 30% 70%;
    grid-template-rows: 260px 260px 260px;
}
#aside {
    background-color: #4FC3F7;
    grid-area: aside;
}
#article1 {
    background-color: #29B6F6;
    grid-area: article1;
}

#article2 {
    background-color: #03A9F4;
    grid-area: article2;
}
#article3 {
    background-color: #039BE5;
    grid-area: article3;
}
#footer {
    height: 100px;
    background-color: #0288D1;
}

@media (max-width: 1300px){

    #wrap {
    width: 96%;
}
    #main {
    grid-template-areas: 
    "aside article1 article1"
    "aside article2 article2"
    "aside article3 article3";
    grid-template-columns: 30% 35% 35%;
    grid-template-rows: 260px 520px;
}
}

@media (max-width: 768px){
    #wrap {
    width: 100%;
}
    #main {
    grid-template-areas: 
    "aside article1 article1"
    "aside article2 article2"
    "aside article3 article3";
    grid-template-columns: 30% 70%;
    grid-template-rows: 390px 390px;
}
    #article3 {
        display: none;
    }
}

@media (max-width: 480px){
    #main {
    grid-template-areas: 
    "aside"
    "article1"
    "article2";
    grid-template-columns: 100%;
    grid-template-rows: 200px 430px 150px;
}
}
728x90
๋ฐ˜์‘ํ˜•

'๋ ˆ์ด์•„์›ƒ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๋ ˆ์ด์•„์›ƒ 04  (3) 2022.07.29
๋ ˆ์ด์•„์›ƒ 03  (5) 2022.07.29
๋ ˆ์ด์•„์›ƒ 02  (5) 2022.07.29
๋ ˆ์ด์•„์›ƒ 01  (5) 2022.07.29

๋Œ“๊ธ€