๋ ์ด์์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;
}
}
๊ฒฐ๊ณผ
See the Pen layout05_05 by mj0614k (@mj0614k) on CodePen.
'WebSite' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์น์ฌ์ดํธ ๋ง๋ค๊ธฐ : ์นด๋ ์ ํ ๋ ์ด์์02 (12) | 2022.08.09 |
---|---|
์น์ฌ์ดํธ ๋ง๋ค๊ธฐ : ์นด๋ ์ ํ ๋ ์ด์์01 (12) | 2022.08.08 |
๋ ์ด์์(Layout) ์ ํ04 (7) | 2022.07.29 |
๋ ์ด์์(Layout) ์ ํ03 (7) | 2022.07.29 |
๋ ์ด์์(Layout) ์ ํ02 (7) | 2022.07.29 |
๋๊ธ