๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
SITE/LAYOUT

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

by _ํ† ๋งคํ†  2022. 7. 29.
728x90

 

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

์‚ฌ์ด๋“œ๊ฐ€ 2๊ฐœ์ธ ์›น์‚ฌ์ดํŠธ ๊ตฌ์กฐ

float์„ ์ด์šฉํ•œ ๋ ˆ์ด์•„์›ƒ + ๋ฐ˜์‘ํ˜•

float์€ ๋ณธ๋ž˜ ๋ ˆ์ด์•„์›ƒ์˜ ์šฉ๋„๊ฐ€ ์•„๋‹ˆ์—ˆ์œผ๋‚˜ ๋งˆ๋•…ํ•œ ์†์„ฑ์ด ์—†์–ด ์‚ฌ์šฉํ•˜๊ฒŒ๋˜์—ˆ๋‹ค. ๋‘ฅ๋‘ฅ ๋œจ๋Š” ํ˜•ํƒœ๋กœ float ์†์„ฑ์ด ์ ์šฉ์ด ์•ˆ๋œ blockbox๋Š” float๋œ box ๋ฐ‘์œผ๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ ๋œ๋‹ค.
๋•Œ๋ฌธ์— ๋ฐฐ์น˜์ด๋™์ด ํ•„์š”ํ•œ ์š”์†Œ์— float์„ ์ด์šฉํ•˜๋ฉด ์„ธ๋กœ๋กœ๋งŒ ๋ฐฐ์น˜๋˜๋˜ ์š”์†Œ๋ฅผ ๊ฐ€๋กœ๋กœ ๋‚˜๋ž€ํžˆ ๋ฐฐ์น˜ํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค.

์ฃผ ์‚ฌ์šฉ ์†์„ฑ
float: left; - ์š”์†Œ๋ฅผ ์œ„๋กœ ๋œจ๊ฒŒ ํ•˜์—ฌ ์™ผ์ชฝ์œผ๋กœ ๋ฐฐ์น˜ํ•ด์ฃผ๋Š” ์†์„ฑ์œผ๋กœ ์ž์‹ ์ด ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ์ฒซ๋ฒˆ์งธ ์™ผ์ชฝ์— ๋ฐฐ์น˜๊ฐ€ ๋œ๋‹ค.
clear: both; - float์„ ํ•œ ์š”์†Œ์•„๋ž˜๋กœ ๋‹ค๋ฅธ ์š”์†Œ๊ฐ€ ์ˆจ์–ด๋ฒ„๋ฆฌ๋Š” ๋ฒ„๊ทธ๋ฅผ ์žก์•„์ฃผ๋Š” ์—ญํ• ์˜ ์†์„ฑ ๋ณดํ†ต footer์™€ ๊ฐ™์€ ํ•˜๋‹จ ์š”์†Œ์— ์Šคํƒ€์ผ์„ ์ ์šฉํ•œ๋‹ค.

* {
    margin: 0;
    padding: 0;
}
body {
    background-color: bisque;
}
#wrap {
    width: 1200px;
    margin: 0 auto;
}
#header {
    width: 100%;
    height: 100px;
    background-color: #C8E6C9;
}
#nav {
    width: 100%;
    height: 100px;
    background-color: #A5D6A7;
}
#main {
    width: 100%;
}
#aside {
    width: 25%;
    height: 780px;
    background-color: #81C784;
    float: left;
}
#section {
    width: 50%;
    height: 780px;
    background-color: #66BB6A;
    float: left;
}
#article {
    width: 25%;
    height: 780px;
    background-color: #4CAF50;
    float: left;
}
#footer {
    width: 100%;
    height: 100px;
    background-color: #43A047;
    clear: both;
}

/* ๋ฏธ๋””์–ด์ฟผ๋ฆฌ */
@media (max-width: 1220px){
    #wrap{
        width: 96%;
    }
}
@media (max-width: 768px){
    #wrap{
        width: 100%;
    }
    #aside {
        width: 30%;
        height: 630px;
    }
    #section {
        width: 70%;
        height: 630px;
    }
    #article {
        width: 100%;
        height: 150px;
    }
}
@media (max-width: 480px){
    #wrap{
        width: 100%;
    }
    #aside {
        width: 100%;
        height: 200px;
    }
    #section {
        width: 100%;
        height: 430px;
    }
}

flex์„ ์ด์šฉํ•œ ๋ ˆ์ด์•„์›ƒ + ๋ฐ˜์‘ํ˜•

๋ ˆ์ด์•„์›ƒ์˜ ๋ฐฐ์น˜๋ฅผ ์œ„ํ•ด ๋‚˜์˜ค๊ฒŒ ๋œ ์†์„ฑ์œผ๋กœ ๋ฐฐ์น˜ํ•˜๋Š” ๋ฐ ์žˆ์–ด ๊ฐ„ํŽธํ•˜๋‹ค.
float๊ณผ ๋‹ฌ๋ฆฌ ๋ฐฐ์น˜๊ฐ€ ํ•„์š”ํ•œ ๊ฐ ์š”์†Œ์— ์ ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๊ทธ ์š”์†Œ๋“ค์„ ํ’ˆ๊ณ  ์žˆ๋Š” ๋ถ€๋ชจ ์š”์†Œ์—๊ฒŒ ์Šคํƒ€์ผ์„ ์„ ์–ธํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
๋•Œ๋ฌธ์— ๊ฐ ์„น์…˜๊ณผ ๊ตฌ์กฐ๋ฅผ ์ž˜ ํŒŒ์•…ํ•˜์—ฌ ๋ถ€๋ชจ ์ž์‹ ๊ด€๊ณ„์— ๋Œ€ํ•œ ๋งˆํฌ์—…์„ ์ž˜ ํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๋‹ค.

์ฃผ ์‚ฌ์šฉ ์†์„ฑ
display: flex; - display๋Š” ์›นํŽ˜์ด์ง€์—์„œ ๋ ˆ์ด์•„์›ƒ ๋ฐ ์š”์†Œ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณด์ด๋Š”๊ฐ€๋ฅผ ์„ ์–ธํ•ด์ฃผ๋Š” ์†์„ฑ์œผ๋กœ ์ฆ‰ ํ•ด๋‹น ์š”์†Œ๋ฅผ flex ์Šคํƒ€์ผ๋กœ ๋ณด์ด๊ฒŒ ํ•˜๋Š” ์†์„ฑ
flex-wrap: wrap; - flex์†์„ฑ์„ ํ†ตํ•ด ๋ฐฐ์น˜ํ•œ ์š”์†Œ๊ฐ€ ์ž˜ ์ ์šฉ๋˜๋„๋ก ํ•ด์ฃผ๋Š” ์†์„ฑ์œผ๋กœ ์ ์šฉํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ๋ฐฐ์น˜ ์ ์šฉ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค.

* {
    margin: 0;
    padding: 0;
}
body {
    background-color: bisque;
}
#wrap {
    width: 1200px;
    margin: 0 auto; 
}
#header {
    /* width 100%๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๊ธฐ ๋•Œ๋ฌธ์— ์ง€์›Œ๋„ ๋ฌด๋ฐฉ! */
    height: 100px;
    background-color: #C8E6C9;
}
#nav {
    height: 100px;
    background-color: #A5D6A7;
}
#main {
    display: flex;
    flex-wrap: wrap;
}
#aside {
    width: 25%;
    height: 780px;
    background-color: #81C784;
}
#section {
    width: 50%;
    height: 780px;
    background-color: #66BB6A;
}
#article {
    width: 25%;
    height: 780px;
    background-color: #4CAF50;
}
#footer {
    height: 100px;
    background-color: #43A047;
}

/* ๋ฏธ๋””์–ด์ฟผ๋ฆฌ */
@media (max-width: 1220px){
    #wrap {
        width: 96%;
    }
}
@media (max-width: 768px){
    #wrap {
        width: 100%;
    }
    #aside {
        width: 30%;
        height: 630px;
    }
    #section {
        width: 70%;
        height: 630px;
    }
    #article {
        width: 100%;
        height: 150px;
    }
}
@media (max-width: 480px){
    #aside {
        width: 100%;
        height: 200px;
    }
    #section {
        width: 100%;
        height: 430px;
    }
}

grid์„ ์ด์šฉํ•œ ๋ ˆ์ด์•„์›ƒ + ๋ฐ˜์‘ํ˜•

flex์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ถ€๋ชจ ์ปจํ…Œ์ด๋„ˆ์—๊ฒŒ ์†์„ฑ์„ ๋ถ€์—ฌํ•ด์ค€๋‹ค.
ํ•˜์ง€๋งŒ grid๋Š” flex์™€ ๋‹ค๋ฅด๊ฒŒ 2๊ฐœ ์ถ•์„ ๋ชจ๋‘ ํ™œ์šฉํ•˜์—ฌ ๊ฒฉ์ž(#) ์œ„์— ์•„์ดํ…œ์„ ๋ฐฐ์น˜ํ•˜๋Š” ๋ ˆ์ด์•„์›ƒ ๋ฐฉ์‹์ด๋‹ค.
๋ณต์žกํ•œ ๊ตฌ์กฐ์˜ ์›น์„ ๊ตฌ์„ฑํ•˜๋ ค๋ฉด grid ๋ ˆ์ด์•„์›ƒ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ํšจ์œจ์ ์ด๋‹ค.

์ฃผ ์‚ฌ์šฉ ์†์„ฑ
display: gird; - ๋ ˆ์ด์•„์›ƒ ๋ฐ ์š”์†Œ๋ฅผ grid ์Šคํƒ€์ผ๋กœ ๋ณด์ด๊ฒŒ ํ•˜๋Š” ์†์„ฑ
grid-template-areas - ๋ ˆ์ด์•„์›ƒ์„ #๊ณผ ๊ฐ™์€ ๊ฒฉ์ž๋กœ ๋‚˜๋ˆ„์–ด์„œ ๊ตฌ์กฐ๋ฅผ ๋‚˜๋ˆ„์–ด ์ฃผ๋Š” ์—ญํ• 
grid-template-columns: ; - ๊ฒฉ์ž๋กœ ๋‚˜๋ˆˆ ์š”์†Œ์˜ ๊ฐ€๋กœ ๊ฐ’์„ ์ •ํ•ด์ฃผ๋Š” ์†์„ฑ
grid-template-rows: ; - ๊ฒฉ์ž๋กœ ๋‚˜๋ˆˆ ์š”์†Œ์˜ ์„ธ๋กœ ๊ฐ’์„ ์ •ํ•ด์ฃผ๋Š” ์†์„ฑ
grid-area: ; - ์ž์‹ ์ปจํ…Œ์ด๋„ˆ์—๊ฒŒ ๋ถ€๋ชจ์—๊ฒŒ ๋„ฃ์€ ์Šคํƒ€์ผ์ด ์ ์šฉ๋  ์ˆ˜ ์žˆ๋„๋ก ์ด๋ฆ„์„ ๋ถ€์—ฌํ•ด์ฃผ๋Š” ์†์„ฑ

* {
    margin: 0;
    padding: 0;
}
body {
    background-color: bisque;
}
#wrap {
    width: 1200px;
    margin: 0 auto; 
}
#header {
    height: 100px;
    background-color: #C8E6C9;
}
#nav {
    height: 100px;
    background-color: #A5D6A7;
}
#main {
    /* ๋‚˜๋ˆ ์ง€๋Š” ํƒœ๊ทธ์˜ ๋ถ€๋ชจ ํƒœ๊ทธ๊ฐ€ main์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๋ฆฌ๋“œ ์†์„ฑ์„ ์—ฌ๊ธฐ์— ์ฃผ๋Š” ๊ฒƒ! */
    display: grid;
    grid-template-areas: 
    "aside section article"
    ;
    grid-template-columns: 25% 50% 25%;
    grid-template-rows: 780px;
}
#aside {
    background-color: #81C784;
    grid-area: aside;
}
#section {
    background-color: #66BB6A;
    grid-area: section;
}
#article {
    background-color: #4CAF50;
    grid-area: article;
}
#footer {
    height: 100px;
    background-color: #43A047;
}

/* ๋ฏธ๋””์–ด์ฟผ๋ฆฌ */
@media (max-width: 1220px){
    #wrap {
        width: 96%;
    }
}
@media (max-width: 768px){
    #wrap {
        width: 100%;
    }
    #main {
        grid-template-areas: 
        "aside section"
        "article article"
        ;
        grid-template-columns: 30% 70%;
        grid-template-rows: 780px 150px; 
    }
    #aside {
        grid-area: aside;
    }
    #section {
        grid-area: section;
    }
    #article {
        grid-area: article;
    }
}
@media (max-width: 480px){
    #main {
        grid-template-areas: 
        "aside"
        "section"
        "article"
        ;
        grid-template-columns: 100%;
        grid-template-rows: 200px 430px 150px; 
    }
    #aside {
        width: 100%;
        height: 200px;
    }
    #section {
        width: 100%;
        height: 430px;
    }
}
728x90

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

๋ ˆ์ด์•„์›ƒ05  (2) 2022.08.05
๋ ˆ์ด์•„์›ƒ04  (4) 2022.07.29
๋ ˆ์ด์•„์›ƒ03  (4) 2022.07.29
๋ ˆ์ด์•„์›ƒ01  (5) 2022.07.27

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css