Front-end/100DaysOfCode
[100DaysOfCode] 23๊ฐ - 24๊ฐ
year.number
2022. 8. 17. 23:52
๐ก ๋ฐ์ํ ์น์ฌ์ดํธ ๋ง๋ค๊ธฐ
๋ฏธ๋์ด ์ฟผ๋ฆฌ
๋ฏธ๋์ด์ฟผ๋ฆฌ ์์ฑ๋ฒ
@media (min-width or max-width: 1200px) {
p {
font-size: 2rem;
}
}
max-width
Desktop ๋จผ์ ์์ ํ Mobile ์์
min-width
Mobile ๋จผ์ ์์ ํ Desktop ์์
๋ฐ์ํ์น & ํ๋ฒ๊ฑฐ ๋ฉ๋ด๋ฅผ ๋ง๋ค์ด๋ณด์!
HTML ํ๊ทธ
<body>
<header>
<div class="logo">WEBFOOD</div>
<nav>
<ul>
<li>Browse Meals</li>
<li>My Orders</li>
</ul>
</nav>
<a href="#side-drawer" class="menu-btn">
<span></span>
<span></span>
<span></span>
</a>
</header>
<aside id="side-drawer">
<header>
<a href="#" class="menu-btn">
<span></span>
<span></span>
<span></span>
</a>
</header>
<nav>
<ul>
<li><a href="">Browse Meals</a></li>
<li><a href="">My Orders</a></li>
</ul>
</nav>
</aside>
CSS ํ๊ทธ
/* *************************************************************** */
/* ham menu */
.menu-btn {
width: 2rem;
height: 2rem;
display: flex;
flex-direction: column;
justify-content: space-around;
display: none;
}
.menu-btn span {
width: 100%;
height: 3px;
background-color: #fff;
}
header ul {
display: flex;
list-style-type: none;
line-height: 0.5rem;
}
header ul li {
margin-left: 2.5rem;
font-size: 1.2rem;
font-family: 'Raleway', sans-serif;
font-weight: 300;
}
header ul li:hover {
color: #ff7043;
cursor: pointer;
}
/* *************************************************************** */
/* drawer */
#side-drawer {
width: 100%;
height: 100%;
background-color: #1f0665;
position: fixed;
top: 0;
left: 0;
display: none;
}
#side-drawer:target {
display: block;
}
#side-drawer header {
display: flex;
align-items: center;
padding: 1.5rem 5.5rem;
justify-content: flex-end;
height: 2.5rem;
background-color: #b1ffb1;
}
#side-drawer nav ul {
font-size: 2.5rem;
text-decoration: none;
list-style-type: none;
margin: 0 auto;
padding: 4rem 1rem;
display: flex;
flex-direction: column;
align-items: center;
margin-top: 2rem;
}
#side-drawer ul li {
margin-top: 3rem;
}
#side-drawer ul li a {
text-decoration: none;
color: white;
}
#side-drawer ul li a:hover {
color: #FF7043;
}
Desktop -> Mobile ์์์ด๊ธฐ ๋๋ฌธ์ ํ๋ฉด์ด ์ค์ด๋ค์์ ๋๋ง ๋ณด์ด๋ ์์๋
display: none; ํด์ค๋ค
๋ฏธ๋์ด ์ฟผ๋ฆฌ
@media (max-width: 768px) {
.foodBox {
grid-template-columns: 1fr;
gap: 6rem;
}
main h1 {
font-size: 2.3rem;
}
main h3 {
font-size: 1.5rem;
}
header nav {
display: none;
}
.menu-btn {
display: flex;
}
}
๊ฐ์์์ ์ ํ์ :target
์์์ #id์ url์ ์๋ #์ด ๊ฐ์ ๋ ์ ์ฉํ ์ ์๋ค
- ๊ธฐ์กด display: none ์ํ์๋ค๊ฐ ํ๋ฒ๊ฑฐ ๋ฉ๋ด๊ฐ ํด๋ฆญ๋์์ ๋ display: block ์์ฑ์ด ๋์ด ํ๋ฉด์ ๋ณด์ด๋๋ก ํ๋ค
1๏ธโฃ id๋ก ์ต์ปค ํ๊ทธ๋ฅผ ์ฐธ์กฐํด์ ๋ด๋ถ ๋งํฌ์ ๊ธฐ์กด ์นํ์ด์ง์์ ๋ด๋ถ ์ฐธ์กฐ๋ฅผ ๋ง๋ค ์ ์๋ค
2๏ธโฃ target ๊ฐ์ ์ ํ์๋ฅผ ์ด์ฉํด์ id๊ฐ ๋ธ๋ผ์ฐ์ ์ ์ถ๊ฐ๋๋ฉด ํน์ ์คํ์ผ์ ์ฌ์ฉํ ์ ์๊ฒ ํ๋ค