๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
WebSite

๋ ˆ์ด์•„์›ƒ(Layout) ์œ ํ˜•05

by ์ฝ”ํŒŒ์นด 2022. 7. 29.
728x90

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

์ด๋ฒˆ ๋ ˆ์ด์•„์›ƒ์€ ์ „์ฒด ์˜์—ญ์ด ๋“ค์–ด๊ฐ„ ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค. ์‹ค์ œ ์‚ฌ์ดํŠธ์—์„œ ์ด๋Ÿฌํ•œ ๊ตฌ์กฐ๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋ฉฐ, ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋งŒ๋“ค์–ด์„œ ๊ฐ€์šด๋ฐ ์˜์—ญ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์˜ ๋ ˆ์ด์•„์›ƒ์„ 3๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ์ž‘์—…ํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

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

'float'๋ผ๋Š” ๋‹จ์–ด๋Š” ์‚ฌ์ „์ ์œผ๋กœ๋Š”'๋œจ๋‹ค'๋ผ๋Š” ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์›นํŽ˜์ด์ง€์—์„œ ์ด๋ฏธ์ง€๋ฅผ ์–ด๋–ป๊ฒŒ ๋„์›Œ์„œ ํ…์ŠคํŠธ์™€ ํ•จ๊ป˜ ๋ฐฐ์น˜ํ•  ๊ฒƒ์ธ์ง€์— ๋Œ€ํ•œ ์†์„ฑ์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, float๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์˜์—ญ์ด ๊นจ์ง€๋Š” ๋ฒ„๊ทธ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜์—ญ ๊นจ์ง์„ ๋ฐฉ์ง€ํ•˜๋Š” 3๊ฐ€์ง€ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

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

* {
    margin: 0;
}

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

#nav {
    height: 100px;
    background-color: #B9AAA5;
}
                    
#main {
    height: 780px;
    background-color: #886F65;
}
                    
#footer {
    height: 100px;
    background-color: #4E342E;
}
                    
.container {
    width: 1200px;
    height: inherit;
    background-color: rgba(0, 0, 0, 0.3);
    margin: 0 auto;
}
                    
.contents .cont1 {
    width: 100%;
    height: 100px;
    background-color: #74574A;
}
                    
.contents .cont2 {
    width: 100%;
    height: 200px;
    background-color: #684D43;
    float: left;
}
                    
.contents .cont3 {
    width: 50%;
    height: 480px;
    background-color: #594139;
    float: left;
}
                    
.contents .cont4 {
    width: 50%;
    height: 480px;
    background-color: #4A352F;
    float: left;
}
                    
/* clearfix */
.clearfix::before,
.clearfix::after {
    content: ''; /* ๊ฐ€์ƒ์š”์†Œ */
    display: block;
    line-height: 0;
}
                    
.clearfix::after {
    clear: both;
}
                    
@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 ์†์„ฑ์„ ์ด์šฉํ•œ ๋ ˆ์ด์•„์›ƒ

'flex' ์†์„ฑ์€ 'flexible'์˜ ์ค„์ž„๋ง๋กœ, ์œ ๋™์ ์ธ ๋ ˆ์ด์•„์›ƒ์„ ์†์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค๋Š” ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. container์™€ item๋“ค์ด ๋ถ€๋ชจ์™€ ์ž์‹ ๊ด€๊ณ„์ผ ๋•Œ, container์— display:flex; ํ˜น์€ display:inline-flex;์†์„ฑ์„ ์คŒ์œผ๋กœ์จ flexbox ๋ ˆ์ด์•„์›ƒ์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

* {
    margin: 0;
}

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

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

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

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

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

.contents .left .cont1 {
    width: 100%;
    height: 100px;
    background-color: #74574A;
}
.contents .right {
    display: flex;
    flex-wrap: wrap;
}
.contents .right .cont2 {
    width: 100%;
    height: 200px;
    background-color: #684D43;
}
.contents .right .cont3 {
    width: 50%;
    height: 480px;
    background-color: #594139;
}
.contents .right .cont4 {
    width: 50%;
    height: 480px;
    background-color: #4A352F;
}
                
/*  ๋ฏธ๋””์–ด์ฟผ๋ฆฌ */
                
@media(max-width: 1220px) {
    .container {
        width: 96%;
    }
                
    .contents {
        display: flex;
    }
                
    .contents .left {
        width: 30%;
    }
                
    .contents .left .cont1 {
        width: 100%;
        height: 780px;
    }
                
    .contents .right {
        width: 70%;
        height: 780px;
    }
                
    .contents .right .cont2 {
        width: 100%;
        height: 390px;
    }
                
    .contents .right .cont3 {
        width: 50%;
        height: 390px;
    }
                
    .contents .right .cont4 {
        width: 50%;
        height: 390px;
    }
}
                
@media(max-width: 768px) {
    .container {
        width: 100%;
    }
                
    .contents .right .cont2 {
        width: 100%;
        height: 260px;
    }
                
    .contents .right .cont3 {
        width: 100%;
        height: 260px;
    }
                
    .contents .right .cont4 {
        width: 100%;
        height: 260px;
    }
}
                
@media(max-width: 480px) {
    .contents {
        flex-wrap: wrap;
    }
                
    .contents .left {
        width: 100%;
        height: 150px;
    }
                
    .contents .left .cont1 {
        width: 100%;
        height: 150px;
    }
                
    .contents .right {
        width: 100%;
        height: 630px;
    }
                
    .contents .right .cont2 {
        height: 210px;
    }
                
    .contents .right .cont3 {
        height: 210px;
    }
                
    .contents .right .cont4 {
        height: 210px;
    }
}

grid ์†์„ฑ์„ ์ด์šฉํ•œ ๋ ˆ์ด์•„์›ƒ

'grid'๋Š” ํŽ˜์ด์ง€๋ฅผ ์—ฌ๋Ÿฌ ์ฃผ์š” ์˜์—ญ์œผ๋กœ ๋‚˜๋ˆ„๊ฑฐ๋‚˜, ํฌ๊ธฐ์™€ ์œ„์น˜ ๋ฐ ๋ฌธ์„œ ๊ณ„์ธต ๊ตฌ์กฐ์˜ ๊ด€์ ์—์„œ HTML ๊ธฐ๋ณธ ์š”์†Œ๋กœ ์ž‘์„ฑ๋œ ์ฝ˜ํŠธ๋กค ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ์ •์˜ํ•˜๋Š” ๋ฐ์— ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. grid ๋ ˆ์ด์•„์›ƒ์€ table๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์„ธ๋กœ ์—ด๊ณผ ๊ฐ€๋กœ ํ–‰์„ ๊ธฐ์ค€์œผ๋กœ ์š”์†Œ๋ฅผ ์ •๋ ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

* {
    margin: 0;
}

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

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

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

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

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

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

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

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

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

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

@media (max-width: 1220px) {
    .container {
        width: 96%;
    }
    
    .contents {
        grid-template-areas:
            "cont1 cont2 cont2"
            "cont1 cont3 cont4";
        grid-template-columns: 1fr 1fr 1fr;
        grid-template-rows: repeat(2, 1fr);
    }
}
            
@media (max-width: 768px) {
    .container {
        width: 100%;
    }

    .contents {
        grid-template-areas:
            "cont1 cont2"
            "cont1 cont3"
            "cont1 cont4";
        grid-template-columns: 30% 70%;
        grid-template-rows: repeat(3, 1fr);
    }
}
            
@media (max-width: 480px) {
    .contents {
        grid-template-areas:
            "cont1"
            "cont2"
            "cont3"
            "cont4";
        grid-template-columns: 100%;
        grid-template-rows: 150px 210px 210px;
    }
}

๊ฒฐ๊ณผ

728x90

๋Œ“๊ธ€

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๐Ÿฆ™

CSS
๊ด‘๊ณ  ์ค€๋น„์ค‘