웹사이트 따라만들기, 반응형 헤더편 | 프론트엔드 개발자 입문편: HTML, CSS, Javascript

HTML, CSS 2020. 12. 30. 15:20
반응형

www.youtube.com/watch?v=X91jsJyZofw&list=PLv2d7VI9OotQ1F92Jp9Ce7ovHEsuRQB3Y&index=14

fonts.google.com/specimen/Source+Sans+Pro?query=source+sans+pro&sidebar.open=true&selection.family=Source+Sans+Pro:wght@600

 

Google Fonts

Making the web more beautiful, fast, and open through great typography

fonts.google.com

www.notion.so/277f2906743742ae8f19b6494581058f

 

프론트엔드 입문자를 위한 영상 순서

공부 법

www.notion.so

fontawesome.com/icons/bars?style=solid

 

Font Awesome

The world’s most popular and easiest to use icon set just got an upgrade. More icons. More styles. More Options.

fontawesome.com

<!DOCTYPE html>
<html lang="kr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <script src="https://kit.fontawesome.com/3442ebfa65.js" crossorigin="anonymous"></script>
    <title>Nav bar</title>
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@600&display=swap" rel="stylesheet">
    <script src="main.js" defer></script>
</head>
<body>
    <nav class="navbar">
        <div class="navbar__logo">
            <i class="fab fa-accusoft"></i>
            <a href="">DreamCoding</a>
        </div>

        <ul class="navbar__menu">
            <li><a href="">Home</a></li>
            <li><a href="">Gallery</a></li>
            <li><a href="">Weddings</a></li>
            <li><a href="">FAQ</a></li>
            <li><a href="">Bookings</a></li>

        </ul>

        <ul class="navbar__icons">
            <li><i class="fab fa-instagram-square"></i></li>
            <li><i class="fab fa-facebook-f"></i></li>
        </ul>

        <a href="#" class="navbar__toggleBtn">
            <i class="fas fa-bars"></i>
        </a>
    </nav>
</body>
</html>
:root {
  --text-color: #f0f4f5;
  --background-color: #263343;
  --accent-color: #d49466;
}
body {
  margin: 0;
  font-family: "Source Sans Pro";
}
a {
  text-decoration: none;
  color: var(--text-color);
}
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--background-color);
  padding: 8px 12px;
}

.navbar__logo {
  font-size: 24px;
  color: var(--text-color);
}

.navbar__logo i {
  color: var(--accent-color);
}

.navbar__menu {
  display: flex;
  list-style: none;
  padding-left: 0;
}

.navbar__menu li {
  padding: 8px 12px;
}

.navbar__menu li:hover {
  background-color: var(--accent-color);
  border-radius: 4px;
}

.navbar__icons {
  list-style: none;
  color: var(--text-color);
  display: flex;
  padding-left: 0;
}

.navbar__icons li {
  padding: 8px 12px;
}

.navbar__toggleBtn {
  display: none;
  position: absolute;
  right: 32px;
  font-size: 24px;
  color: var(--accent-color);
}

@media screen and (max-width: 768px) {
  .navbar {
    flex-direction: column;
    align-items: flex-start;
    padding: 8px 24px;
  }
  .navbar__menu {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
  }

  .navbar__menu li {
    width: 100%;
    text-align: center;
  }

  .navbar__icons {
    display: none;
    justify-content: center;
    width: 100%;
  }

  .navbar__toggleBtn {
    display: block;
  }

  .navbar__menu.active,
  .navbar__icons.active {
    display: flex;
  }
}
const toggleBtn = document.querySelector(".navbar__toggleBtn");
const menu = document.querySelector(".navbar__menu");
const icons = document.querySelector(".navbar__icons");

toggleBtn.addEventListener("click", () => {
  menu.classList.toggle("active");
  icons.classList.toggle("active");
});

반응형
: