반응형메뉴 resize할 때 질문이요

반응형메뉴 resize할 때 질문이요

QA

반응형메뉴 resize할 때 질문이요

본문

1846519728_1678771054.2931.png

반응형 메뉴를 만들었습니다. resize if문으로 작업했습니다 새로고침할땐 괜찮은데 화면 크기가 줄어들거나, 늘어났을때 문제가 있네요.  

수정하려면 어떻게 해야되나요ㅠㅠ

코드는 아래링크에 있습니다!

 

https://codepen.io/aldo814-the-bold/pen/poOLRNX

 

이 질문에 댓글 쓰기 :

답변 1

반응형 예제인데요. 골격만 있습니다. 만드시는데 참조해 보세요. 감사합니다.


<!DOCTYPE html>
<html lang="en">
 
<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">
  <title>test03.html</title>
  <!-- Font -->
  <link rel="stylesheet" href="fonts/fonts.css" />
  <!-- Normalize -->
  <link rel="stylesheet" href="css/normalize.css" />
  <!-- Custom -->
  <link rel="stylesheet" href="css/utility.css" />
  <link rel="stylesheet" href="css/style.css" />
  <link rel="stylesheet" href="css/reponsive.css" />
  <style>
    html,
    body {
      height: 100%;
      margin: 0;
      padding: 0;
    }
 
    .wrapper {
      height: 100%;
      display: flex;
      flex-direction: column;
    }
 
    header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #333;
      color: #fff;
      padding: 10px;
    }
 
    .logo {
      font-size: 24px;
      cursor: pointer;
    }
 
    .menu-toggle {
      display: none;
      cursor: pointer;
    }
 
    .menu-toggle span {
      display: block;
      width: 25px;
      height: 3px;
      margin: 5px 0;
      background-color: #fff;
    }
 
    .menu {
      display: flex;
    }
 
    .menu-close {
      display: none;
    }
 
    .menu ul {
      display: flex;
      list-style: none;
      margin: 0;
      padding: 0;
    }
 
    .menu li {
      margin-right: 20px;
    }
 
    .menu a {
      color: #fff;
      text-decoration: none;
    }
 
    .container {
      flex: 1;
      padding: 20px;
    }
 
    .footer {
      flex-shrink: 0;
      height: 60px;
      background-color: #333;
      color: #fff;
      text-align: center;
      padding: 10px;
    }
 
    @media screen and (max-width: 768px) {
      header {
        flex-direction: row;
        align-items: center;
        padding: 20px;
        position: relative;
      }
 
      /* .menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background-color: #333;
      } */
 
      /* .menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 75%;
        height: 100vh;
        background-color: #fff;
        transition: right 0.3s ease-in-out;
      }
 
      .menu li {
        margin-right: 0;
      }
 
      .menu a {
        display: block;
        padding: 10px;
        border-bottom: 1px solid #fff;
      } */

 
      .menu-toggle {
        display: block;
      }
 
      /* .menu-toggle.active {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        width: 25%;
      } */
 
      /* .menu-toggle.active~.menu {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 25%;
        height: auto;
        position: fixed;
        top: 0;
        right: -100%;
        width: 75%;
        height: 100vh;
        background-color: #fff;
        transition: right 0.3s ease-in-out;
      } */
      .menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 75%;
        height: 100vh;
        background-color: #fff;
        transition: right 0.3s ease-in-out;
      }
 
      .menu.active {
        border: 2px solid #ccc;
        right: 0;
        display: flex;
        flex-direction: column;
      }
 
      .menu-toggle {
        background: linear-gradient(#555353, #363535, #303030);
        /*linear-gradient(#cdcdcd, #a8a4a4e0, #dddada);*/
        padding: 10px;
        border: 2px solid #f5f5f5;
        border-radius: 6px;
        box-shadow: inset 0 5px 1px rgba(0, 0, 0, 0.35), 0 5px 5px rgba(0, 0, 0, 0.5), 0 15px 25px rgba(0, 0, 0, 0.35);
      }
 
      .menu-close {
        display: inline-block;
        position: absolute;
        top: 10px;
        right: 10px;
        font-size: 1.5rem;
        border: 1px solid #ccc;
        color: #fff;
        background-color: red;
        width: 35px;
        height: 35px;
        border-radius: 35px;
        /*100%;*/
        /*transparent;*/
        /* margin: 25px 0; */
        /* padding: 25px 0; */
        cursor: pointer;
      }
 
      .menu.active ul {
        flex-direction: column;
        flex-wrap: nowrap;
        /* justify-content: top; */
        flex-shrink: 0;
        position: absolute;
        top: 20px;
        left: 10px;
        width: 100%;
        list-style: none;
        margin: 30px 0;
        padding: 0;
      }
 
      .menu.active li {
        margin-bottom: 10px;
      }
 
      .menu.active li a {
        display: block;
        /* width: 80px; */
        height: 50px;
        padding: 10px;
        background-color: #eee;
        text-decoration: none;
        color: #333;
        line-height: 50px;
      }
    }
  </style>
</head>
 
<body>
  <div class="wrapper">
    <header>
      <div class="logo">
        <h1>Logo</h1>
      </div>
      <a href="#" class="menu-toggle">
        <span></span>
        <span></span>
        <span></span>
      </a>
      <nav class="menu">
        <button class="menu-close">×</button>
        <ul>
          <li><a href="#">Menu 1</a></li>
          <li><a href="#">Menu 2</a></li>
          <li><a href="#">Menu 3</a></li>
        </ul>
      </nav>
    </header>
    <div class="container">
      <h2>Main Content</h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec convallis, quam at vulputate hendrerit, nibh
        nibh suscipit est, nec blandit nunc eros ac tortor.</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec convallis, quam at vulputate hendrerit, nibh
        nibh suscipit est, nec blandit nunc eros ac tortor.</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec convallis, quam at vulputate hendrerit, nibh
        nibh suscipit est, nec blandit nunc eros ac tortor.</p>
 
    </div>
    <footer class="footer">
      <p>© 2023 My Website. All rights reserved.</p>
    </footer>
  </div>
</body>
<script>
  var toggle_menu = document.querySelector('.menu-toggle');
  var menulist = document.querySelector('.menu');
  var menu_close = document.querySelector('.menu-close');
  var loggo_click = document.querySelector('.logo');
 
  loggo_click.addEventListener('click', function () {
    window.location.href = "./test03.html";
  });
 
  toggle_menu.addEventListener('click', function () {
    toggle_menu.classList.toggle('active');
    menulist.classList.toggle('active');
    menu_close.classList.toggle('active');
  });
  menu_close.addEventListener('click', function () {
    toggle_menu.classList.toggle('active');
    menulist.classList.toggle('active');
  });
 
</script>
 
</html>
답변을 작성하시기 전에 로그인 해주세요.
전체 17
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT