๋ ์ด์์ 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 |
๋๊ธ