반응형
HTML과 CSS로 블로그 메뉴 만들기 + 반응형 페이지
HTML과 CSS로 간단하게 블로그 페이지를 만들어보자!
메뉴, 글자 깜빡거리는 기능 등을 넣었고,
반응형 페이지(화면 크기에 따라 요소가 변경됨)으로 만들었다.
코드
<HTML>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="https://i.pinimg.com/550x/5d/90/1f/5d901f30a1ee270123e19b1404165113.jpg" type="image/x-icon" />
<link rel="stylesheet" href="./style.css"/>
<title>양콩 BLOG</title>
</head>
<body>
<section class="intro">
<div class="intro_dark">
<div class="intro_type">
<div><span class="kiss">😘</span>양콩</div>
<div>BLOG<span class="underscore">❤❤❤</span></div>
</div>
</div>
<div class="intro_title"></div>
<div class="intro_title_flip"></div>
</section>
<header class="header">
<h1>
<a class="header_homelink" href="#">
<span class="header_logo">BLOG</span>
</a>
</h1>
<input class="header_menu_btn" type="checkbox">
<nav class="header_nav">
<ul>
<li class="header_nav_item">
<a href="#about">양콩BLOG</a>
</li>
<li class="header_nav_item">
<a href="#diary">일기장</a>
</li><li class="header_nav_item">
<a href="#challenge">챌린지</a>
</li><li class="header_nav_item">
<a href="#career">커리어</a>
</li><li class="header_nav_item">
<a href="#contact">방명록</a>
</li>
</ul>
</nav>
<div class="search">
<input type="text" placeholder="검색어 입력" id="text">
<img id="img" src="https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/icon/search.png">
</div>
</header>
</body>
</html>
<CSS>
body {
margin: 0;
font-family: "Noto Sans KR", sans-serif;
}
.intro{
position: relative;
background-image: url("https://i.pinimg.com/originals/14/f7/b0/14f7b04d6048883fa4749556edf50891.jpg");
background-size: cover;
background-position: center;
}
.intro_dark{
position: absolute;
height: 500px;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align: center;
background-color: rgba(0, 0, 0, 0.67);
}
.intro_type {
display: flex;
gap: 0.32em;
font-size: 2.8em;
font-weight: bold;
color: white;
justify-content: center;
padding: 130px;
}
.intro_type .underscore {
animation: blink;
animation-duration: 350ms;
animation-iteration-count: infinite;
animation-duration: alternate;
}
.intro_type .kiss {
animation: blink;
animation-duration: 350ms;
animation-iteration-count: infinite;
animation-duration: alternate;
}
@keyframes blink {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
[class^="intro_title"] {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 25%;
background-color: rgb(238, 152, 212);
clip-path: polygon(100% 90%, 100% 100%, 0 100%, 0 0);
}
.intro_title_flip {
clip-path: polygon(100% 0, 100% 100%, 0 100%, 0 90%);
opacity: 0.5;
}
@media (max-width: 768px) {
.intro {
height: 100vh;
}
.intro_type{
margin-top: 36vh;
flex-direction: column;
text-align: center;
}
}
@media (min-width: 768px) {
.intro{
height: 500px;
}
.intro_type{
margin-top: 172px;
align-items: center;
}
.intro_type .span{
display: inline-block;
vertical-align: middle;
margin-bottom: 0.25em;
}
}
.header{
display: flex;
position: sticky;
/*스크롤이올라가면 컨텐츠 위로 올라오도록 설정해주는 코드*/
z-index: 2;
top: 0;
height: 72px;
justify-content: space-between;
align-items: center;
background-color: rgb(247, 245, 180);
}
.header_homelink {
display: inline-block;
padding: 0 24px;
height: 72px;
line-height: 72px;
cursor: pointer;
}
.header_logo {
height: 48px;
vertical-align: middle;
margin-bottom: 4px;
font-size: 50px;
}
.header_nav_item {
font-size: 30px;
}
.header_nav_item a{
display: inline-block;
height: 72px;
line-height: 72px;
}
@media (max-width: 768px) {
.header_nav {
display: none;
}
.header_menu_btn{
all:unset;
display: block;
width: 72px;
height: 72px;
background-image: url(/images/menu-button.svg);
background-size: 50%;
background-repeat: no-repeat;
background-position: center;
}
.header_menu_btn:checked{
background-color: rgb(114, 0, 63);
}
.header_menu_btn:checked + .header_nav {
display: inherit;
position: absolute;
top: 72px;
right: 0;
background-color: blueviolet;
padding-bottom: 1em;
box-shadow: 0 2px 2px rgba(255, 255, 255, 0.26);
}
.header_nav_item{
width: 100vh;
text-align: center;
justify-content: center;
}
.header_nav_item a {
width: 100vw;
}
.header_nav_item:not(:last-child) {
border-bottom: 2px solid rgba(255, 255, 255, 0.06);
}
}
@media (min-width: 769px) {
.header_nav_item {
display: inline-block;
position: relative;
}
.header_nav_item:last-child {
margin-right: 1.6em;
}
.header_nav_item a{
padding: 0 0.8em;
}
.header_nav_item ::after {
content: "";
position: absolute;
bottom: 0px;
left: 50%;
width: 0;
height: 0;
background-color: white;
transition: all 350ms;
}
.header_nav_item:hover::after{
left: 0;
width: 100%;
height: 8px;
}
.header_menu_btn {
display:none;
}
}
.search {
position: relative;
width: 200px;
justify-content: center;
float: right;
right: 100px;
}
#text {
width: 100%;
border: 1px solid #bbb;
border-radius: 8px;
padding: 10px 12px;
font-size: 14px;
}
#img {
position : absolute;
width: 17px;
top: 10px;
right: 12px;
margin: 0;
}
결과
See the Pen First blog menu by Kong Yang (@Kong-Yang) on CodePen.
반응형