Problem with the menu button overflowing

I'm exploring the process of designing burger menus for the mobile version of my site. I've successfully created a basic burger menu with some JavaScript assistance, but I encountered an overflow issue. The burger menu functions properly, but there is a horizontal scroll when it's not in use. I know that using position: relative and overflow: hidden could resolve this problem, but I'm unsure which element to apply these properties to. When I attempted to apply them to the parent header element, the burger menu expanded to the full height of the header. I'm struggling to find a solution to prevent this from happening.

HTML:

`<header class="header">
  <div class="header__container">
    <a href="#"
      ><div class="logo__block">
        <img src="img/logo.svg" alt="Logo" /></div
    ></a>
    <nav class="header__nav nav">
      <ul class="nav__list">
        <div class="burger-menu__exit">X</div>
        <li class="nav__item">
          <a href="#" class="nav__link">Home</a>
        </li>
        <li class="nav__item">
          <a href="#" class="nav__link">Features</a>
        </li>
        <li class="nav__item">
          <a href="#" class="nav__link">Pricing</a>
        </li>
        <li class="nav__item">
          <a href="#" class="nav__link">Blog</a>
        </li class="nav__item nav-btn">
      </ul>
    </nav>
    <a class="header-btn" href="#">Get Started</a>
    <div class="burger-menu">
        <div class="line line1"></div>
        <div class="line line2"></div>
        <div class="line line3"></div>
    </div>
  </div>
</header>`

CSS:

`body {
  font-family: "Libre Franklin", sans-serif;
}

[class$="__container"] {
  max-width: 1270px;
  margin: 0 auto;
  padding: 0 15px;
}

.header__container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  line-height: 60px;
  padding-top: 40px;
  padding-bottom: 60px;
}

.header__container:before{
    position: relative;
}

.logo__block {
  display: flex;
  align-items: center;
}

.nav {
  margin-left: auto;
  
}

.nav__list {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
}

.nat__item {
}

.nav-btn {
  display: none;
}

.nav__list > li:not(.nav__item:last-child) {
  margin-right: 100px;
}

.nav__item:last-child {
  margin-right: 79px;
}

.nav__link {
  font-style: normal;
  font-weight: 400;
  font-size: 20px;
}

.nav__link:hover {
  border-bottom: 2px solid black;
}

.btn__block {
  max-width: 286px;
}

.header-btn {
  width: 211px;
  text-align: center;
  border-radius: 10px;
  font-style: normal;
  font-weight: 500;
  font-size: 20px;
  color: white;
  background-color: #ff7143;
  transition: 0.3s;
}

.header-btn:hover {
  background-color: #d1542b;
}

.burger-menu {
  display: none;
  margin-left: 10px;
  cursor: pointer;
}

.burger-menu__exit {
  display: none;
}

.line {
  width: 35px;
  height: 2px;
  background-color: black;
  margin-top: 10px;
}
.line1 {
  margin-top: 0;
}

@media (max-width: 1309px) {
  [class$="__container"] {
    max-width: 1103px;
  }
}

@media (max-width: 1129px) {
  [class$="__container"] {
    max-width: 1000px;
  }

  .nav__list > li:not(.nav__item:last-child) {
    margin-right: 50px;
  }

  .nav__item:last-child {
    margin-right: 79px;
  }
}

@media (max-width: 988.98px) {
  [class$="__container"] {
    max-width: none;
  }

  .burger-menu {
    display: block;
  }

  .header__nav {
    background-color: #5454d4;
    z-index: 9999;
  }
  .nav {
    position: absolute;
    top: 0;
    left: 100%;
    right: -100%;
    z-index: 999;
    min-width: 375px;
    height: 100vh;
    padding-top: 30px;
    color: #ff7143;
    transition: 1s;
  }

  .nav__list {
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .nav__list a {
    color: #ff7143;
  }

  .nav__list a:hover {
    border-bottom: 2px solid #ff7143;
  }

  .nav__list > li:not(.nav__item:last-child) {
    margin-right: 0;
  }

  .nav__item:last-child {
    margin-right: 0;
  }

  .header-btn {
    margin-left: auto;
  }

  .burger-menu__exit {
    display: block;
    cursor: pointer;
    position: absolute;
    top: 0;
    right: 18px;
    font-size: 40px;
  }
}

@media (max-width: 512.98px) {
  .header-btn {
    display: none;
  }
}

@media (max-width: 369.98px) {
  .nav {
    min-width: 100%;
  }
}`

JS:

    const mobileNav = document.querySelector(".nav");
const headerButton = document.querySelector(".header-btn");
const headerContainer = document.querySelector(".header__container");

document.querySelector(".burger-menu").addEventListener("click", () => {
  mobileNav.style.right = 0;
});

document.querySelector(".burger-menu__exit").addEventListener("click", () => {
  mobileNav.style.right = -100 + "%";
});

Appreciate the assistance!

Answer №1

The problem was resolved by implementing a separate navigation for the burger menu outside of the header section and including the CSS code

position: relative; overflow: hidden;
in the html and body elements.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guidelines for simultaneously modifying two dropdown select options

Is it possible to have one dropdown automatically change its value based on the selection made in another dropdown? For instance, if 'Value 1' is chosen from 'dropdown 1', can we set 'dropdown 2' to automatically display the ...

Arranging Pictures Beside Text Using CSS

I have a puzzling issue that I cannot seem to find an answer for despite the countless times it has been asked. In my footer, there is aligned copyright text, and I am attempting to add 3 logos to the right of it without any line breaks. However, when the ...

Tips for altering the color of an image using CSS attributes

I am looking to create a male Head component in this design draft and modify the CSS according to the skin prop. I have attempted to use filter and mix-blend-mode properties, but have not found a solution yet. Any guidance on how to achieve this would be ...

What is the best way to delete a container when its child element includes a specific string?

I run a website that compiles video clips from various sources, including YouTube. Occasionally, some clips appear as private videos. I am looking to use jQuery to apply the display:none; property to the entire div when the class a.colorbox.cboxElement con ...

Resize the shape of an image's polygon

Is there a way to independently scale a specific polygon of an image on hover? For example, I have a world map and I would like to enlarge a country when hovering over it, then return it to its original size when no longer hovering. I am familiar with us ...

What is causing this JavaScript alert to malfunction?

My current project involves working with ASP.NET and in the view, I have a code snippet that is causing some issues. When I attempt to use Sweet Alert outside of the function, it works perfectly fine. Similarly, if I switch out Sweet Alert for a regular al ...

After all other content has been fully loaded, jQuery UI is then loaded onto

For a while now, I've been following a YouTuber's JQuery UI tutorial. Every time I refresh the page, my HTML loads first and then my CSS fills in, causing a momentary flash of HTML and CSS without the UI. Is this normal? Can it be prevented? Her ...

Responsive Alignment of Slanted Edges using CSS

I have been working on creating a responsive diagonal layout with slanted shapes (refer to the image attached). However, I'm facing a challenge with aligning the edges smoothly at different screen sizes, especially when the rows grow and the screen re ...

Simple steps for integrating JavaScript ads into your WordPress website

Received an advertisement from my client, a 300x250 ad in ad folder consisting of 1 HTML file, 1 JavaScript file, and 1 images folder. Questioning how to integrate these files into the side panel of my Wordpress website's homepage. I've spent a ...

Linking the location of the pop-up to the currently selected text box

I am currently experimenting with setting the top and left values relative to the selected_element (which is active at the time of triggering the popup) in a manner similar to a tooltip. I attempted to use $().position() in combination with jQuery, but it ...

Searching for text in a Python Selenium input field and retrieving suggested values can be achieved by using certain methods and commands

When you type a term like "apple" into the search bar on , a dropdown menu with search suggestions appears. I am attempting to retrieve a list, dictionary, or dataframe of the values in that dropdown box. For example: {'AAPL':['Apple Inc ...

Limiting the display of every item in Angular ngFor

I'm currently working with Angular and I have the following code in my component.html: <div class="card" *ngFor="let item of galleries;" (mouseenter)=" setBackground(item?.image?.fullpath)" (mouseover)="showCount ...

Fixed position not being maintained after clicking the button

Looking for some help with a fixed header issue on my website. The header is supposed to stay at the top while scrolling, which works well. However, when I switch to responsive view, click the menu button, and then go back to desktop view, none of the po ...

What is the proper method to deactivate a hyperlink in Angular 2?

I'm currently developing a web application using Angular2, and I find myself in need of displaying, but making it non-clickable, an <a> element within my HTML. Can anyone guide me on the correct approach to achieve this? Update: Please take no ...

Automatically omitting a selector that mimics a switch

After conducting thorough research, I discovered a variety of solutions using jQuery and Vanilla. While one answer perfectly addressed my issue, it failed to integrate effectively with the rest of my code. So, I decided to modify the code from this Stack O ...

What is the best way to create a scrollable horizontal element using bootstrap?

Here is the specific issue I'm facing: https://i.sstatic.net/oi94N.png The problem is that the icons are wrapping onto 2 lines, which is not the desired outcome. This is what I currently have: <li class="list-group-item participants-grouping-li" ...

Unable to retrieve the value of ng-model using $scope

Having some trouble getting the ng-model value when clicking a button that triggers a function to add each ng-model value to an object. Interestingly, when trying to get the value of $scope.shipNameFirst, it shows up as undefined in the second example. I& ...

Issues with CSS not loading properly on EJS files within subdirectories

This is the structure of my folders (with views located in the root directory): views/contractor/auth/login.ejs When I access that file, the CSS styles are not being applied. The connection to the CSS file, which is located in the public directory in th ...

How can I create a component that dynamically adjusts to different screen sizes

I have developed three child components for the main content area (excluding the header) However, one of the components is not responsive. Below is the code snippet: <div className="row" style={{marginTop:'30px',}}> <div class ...

Executing SQL Query on Button Click Event

I am working with PHP and trying to execute a SQL query when a button is pressed. However, the issue I'm facing is that nothing happens when I click the button! I checked the developer console but there doesn't seem to be any action detected when ...