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

[Layout] ๋ ˆ์ด์•„์›ƒ 05

by ์ฝ”๋”ฉ๊ณต์ฑ… 2022. 7. 29.
๋ฐ˜์‘ํ˜•

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

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

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

๋ ˆ์ด์•„์›ƒ์˜ ํ‹€์„ ์žก์„ ๋•Œ <div> ํƒœ๊ทธ๊ฐ€ ์‚ฌ์šฉ๋˜๋ฉฐ ํ•ด๋‹น ํƒœ๊ทธ๋Š” Block ํ˜•์‹์ด๋ฏ€๋กœ ๊ฐ€๋กœ๋กœ ๋‚˜๋ž€ํžˆ ์ •๋ ฌ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.
์ด๋•Œ ๋‚˜๋ž€ํžˆ ์ •๋ ฌํ•ด์ฃผ๊ณ ์ž ํ•˜๋Š” ์š”์†Œ์˜ CSS ์†์„ฑ์— float: left;๋ฅผ ์ ์–ด์ฃผ๋ฉด ๋‚˜๋ž€ํžˆ ์ •๋ ฌ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

๋‹จ, ์ด ์†์„ฑ์„ ์“ฐ๊ฒŒ ๋  ๊ฒฝ์šฐ, ์†์„ฑ์„ ์ผ๋˜ ์•„๋ž˜์˜ footer์˜ height๊ฐ’์ด 0์ด ๋˜์–ด ๋ณด์ด์ง€ ์•Š๊ฒŒ ๋˜๋Š” ๋ฒ„๊ทธ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”๋ฐ ์ด๋Ÿด ๋•Œ์—๋Š” ๋ณด์ด์ง€ ์•Š๋Š” ํ•ด๋‹น ์š”์†Œ์— clear: both;๋ฅผ ์ ์–ด๋†“์œผ๋ฉด ํ•ด๊ฒฐ๋œ๋‹ค.

clear: both; ์™ธ์—๋„ overflow: hidden; ๋ฐฉ์‹๊ณผ clearfix ์„ค์ • ๋ฐฉ์‹์ด ์žˆ๋Š”๋ฐ ์ด ์ค‘ ๊ฐ€์žฅ ์™„๋ฒฝํ•œ ๋ฐฉ๋ฒ•์€ clearfix ๋ฐฉ์‹์ด๋ฉฐ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์— ๊ธฐ์žฌ๋˜์–ด ์žˆ๋‹ค.

* {
    margin: 0;
    padding: 0;
}
#wrap {}
#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;
    margin: 0 auto;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.15);
}
.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;
}
/* 
    float์œผ๋กœ ์ธํ•œ ์˜์—ญ ๊นจ์ง ๋ฐฉ์ง€๋ฒ•
    1. ๊นจ์ง€๋Š” ์˜์—ญ์— clear: both;๋ฅผ ์„ค์ •ํ•œ๋‹ค.
    2. ๋ถ€๋ชจ๋ฐ•์Šค ์˜์—ญ์— onerflow: hidden;์„ ์„ค์ •ํ•œ๋‹ค. (์• ๋‹ˆ๋ฉ”์ด์…˜ ์‚ฌ์šฉ ์‹œ ๋ถˆ๋ฆฌํ•จ)
    3. clearfix๋ฅผ ์„ค์ •ํ•œ๋‹ค. ๊ฐ€์žฅ ์™„๋ฒฝํ•œ ๋ฐฉ๋ฒ•!
*/
.clearfix::before,
.clearfix::after {
    content: '';
    display: block;
    line-height: 0;
}
.clearfix::after {
    clear: both;
}
/* ๋ฏธ๋””์–ด์ฟผ๋ฆฌ ์“ธ ๋•Œ๋Š” width ํผ์„ผํ…Œ์ด์ง€๋กœ ์ „ํ™˜ํ• ๊ฒƒ */
@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๋กœ ๋ ˆ์ด์•„์›ƒ ์ •๋ ฌ ์‹œ์—๋Š” ๋จผ์ € html์—์„œ๋Š” ์‹œ๋งจํ‹ฑ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๊ณ  ๋ถ€๋ชจ ๋ฐ•์Šค๊ฐ€ ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•˜๋ฉฐ ๊ทธ ๋ถ€๋ชจ ๋ฐ•์Šค ์•ˆ์— display: flex; ์™€ flex-wrap: wrap; ์„ค์ •์„ ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

* {
    margin: 0;
    padding: 0;
}
#wrap {
    width: 100%;
}
#header {
    width: 100%;
    height: 100px;
    background-color: #EEEBE9;
#nav {
    width: 100%;
    height: 100px;
    background-color: #B9AAA5;
#menu {
    width: 100%;
    height: 780px;
    background-color: #886F65;
}
#footer {
    width: 100%;
    height: 100px;
    background-color: #4E342E;
.container {
    width: 1200px;
    height: inherit;
    margin: 0 auto;
    background-color: rgba(0,0,0,0.3);
}
.contents {
    display: flex;
    flex-wrap: wrap;
}
.contents .right {
    width: 1200px;
}
.contents .cont1 {
    width: 100%;
    height: 100px;
    background-color: #74574A;
.contents .left {
    width: 1200px;
    display: flex;
    flex-wrap: wrap;
}
.contents .cont2 {
    width: 100%;
    height: 200px;
    background-color: #684D43;
}
.contents .cont3 {
    width: 50%;
    height: 480px;
    background-color: #594139;
}
.contents .cont4 {
    width: 50%;
    height: 480px;
    background-color: #4A352F;

@media (max-width: 1220px){
    .container {
        width: 96%;
    }
    .contents {
        display: flex;
        flex-wrap: wrap;
    }
    .contents .left {
        width: 30%;
    }
    .contents .cont1 {
        width: 100%;
        height: 780px;
    }
    .contents .right {
        width: 70%;
        display: flex;
        flex-wrap: wrap;
    }
    .contents .cont2 {
        width: 100%;
        height: 390px;
    }
    .contents .cont3 {
        width: 50%;
        height: 390px;
    }
    .contents .cont4 {
        width: 50%;
        height: 390px;
    }
}
@media (max-width: 768px){
    .container {
        width: 100%;
    }
}
@media (max-width: 480px){
    .contents {
        flex-wrap: wrap;
    }
    .contents .left {
        width: 100%;
    }
    .contents .cont1 {
        width: 100%;
        height: 150px;
    }
    .contents .right {
        width: 100%;
        flex-wrap: wrap;
    }
    .contents .cont2 {
        width: 100%;
        height: 210px;
    }
    .contents .cont3 {
        width: 100%;
        height: 210px;
    }
    .contents .cont4 {
        width: 100%;
        height: 210px;
    }
}

๊ฒฐ๊ณผ

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

table์ฒ˜๋Ÿผ ๋ ˆ์ด์•„์›ƒ์„ ์žก์„ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค. display: grid;๋กœ Grid ์‚ฌ์šฉ์„ ํ™œ์„ฑํ™”ํ•˜๋ฉฐ, grid-template-columns์—์„œ๋Š” ์š”์†Œ ๋ฐฐ์น˜ ๊ฐ€๋กœ ๊ธธ์ด๋ฅผ, grid-template-rows์—์„œ๋Š” ์„ธ๋กœ ๊ธธ์ด๋ฅผ ์ง€์ •ํ•ด์ค๋‹ˆ๋‹ค.

* {
    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 {
        display: grid;
        grid-template-areas: 
            "cont1 cont2 cont2"
            "cont1 cont3 cont4";
        /* grid-template-columns: 33.3333% 33.3333% 33.3333% */
        /* grid-template-columns: 1fr 1fr 1fr; */
        grid-template-columns: repeat(3, 1fr); /* ์ž๋™ 3๋“ฑ๋ถ„ */
        /* grid-template-rows: repeat(2, 390px);  */
        grid-template-rows: repeat(2, 1fr); 
    }
}
@media (max-width: 768px) {
    .container {
        width: 100%;
    }
    .contents {
        display: grid;
        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 {
        display: grid;
        grid-template-areas: 
            "cont1"
            "cont2"
            "cont3"
            "cont4";
        grid-template-columns: 100%;
        grid-template-rows: 150px 210px 210px 210px; 
    }
}

๊ฒฐ๊ณผ

๋ฐ˜์‘ํ˜•

'Layout' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Layout] ๋ ˆ์ด์•„์›ƒ 04  (7) 2022.07.29
[Layout] ๋ ˆ์ด์•„์›ƒ 03  (6) 2022.07.29
[Layout] ๋ ˆ์ด์•„์›ƒ 02  (7) 2022.07.29
[Layout] ๋ ˆ์ด์•„์›ƒ 01  (7) 2022.07.29

๋Œ“๊ธ€


Reference Book

JavaScript
HTML
CSS
๊ด‘๊ณ  ์ค€๋น„์ค‘์ž…๋‹ˆ๋‹ค.