Using absolute positioning on elements can result in the page zooming out

While this answer may seem obvious, I have been unable to find any similar solutions online. The problem lies with my responsive navbar, which functions perfectly on larger screens. However, on mobile devices, the entire website appears zoomed out like this: https://i.sstatic.net/KVerf.png. Removing the line right: -200px; resolves the issue, but I still need to move the content off the screen. Is this zoom behavior specific to Next.js, and is there a way to fix it? Thank you for your assistance!

.navigation-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2% 6%;
  background-color: transparent;
}

.nav-links-main {
  flex: 1;
  text-align: right;
}

.nav-links-main a {
  text-decoration: none;
  font-size: 15px;
  color: #fff;
}

.nav-links-main ul li {
  list-style: none;
  display: inline-block;
  padding: 8px 12px;
  position: relative;
}

.nav-links-main ul li::after {
  content: "";
  width: 0%;
  height: 2px;
  background: #f44336;
  display: block;
  margin: auto;
  transition: 0.5s;
}

.nav-links-main ul li:hover::after {
  width: 100%;
}

.bars {
  width: 25px;
  color: #fff;
  cursor: pointer;
  display: none;
}

@media (max-width: 822px) {
  /* make navbar responsive */

  .nav-links-main ul li {
    text-align: center;
    display: block;
  }

  .nav-links-main {
    position: absolute;
    background: #f44336;
    min-height: 100vh;
    width: 200px;
    top: 0;
    text-align: left;
    z-index: 1;
    right: -200px;
  }

  .bars {
    display: block;
  }
}
    <div className="nav-links-main" id="navLinks">
        <ul>
          <li>
            <Link href="/">
              <a>HOME</a>
            </Link>
          </li>
          <li>
            <Link href="about">
              <a>ABOUT</a>
            </Link>
          </li>
          <li>
            <Link href="blog">
              <a>BLOG</a>
            </Link>
          </li>
          <li>
            <Link href="contact">
              <a>CONTACT</a>
            </Link>
          </li>
        </ul>
      </div>

      <a onClick={openMenu}>
        <FontAwesomeIcon icon={faBars} className="bars" />
      </a>
    </div>

Answer №1

To enhance your _app.js file, insert the following code within the head section. If there is an existing meta tag with the name viewport, substitute it with the code below -

<meta name="viewport" content="width=device-width" />

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

Submitting data using JavaScript's POST method

I am facing a challenge with posting Array data to an HTTP connector. My data is structured as follows: var data = [{ key:'myKey', keyName:'myKeyName', value:'value', valueName:'valueName' }, { ...

Building a custom HTML and JavaScript player to showcase multiple videos on a webpage

UPDATE: The solution has been discovered, shared, and marked as the top answer below. In the process of creating my portfolio website using HTML, CSS, and JS, I encountered a challenge regarding the addition of multiple videos on various pages. While fol ...

Whenever a user tries to retrieve a page using ajax and then proceeds to submit the form associated with that page, they encounter

In my addQuestions.php file, I have four options available - single, multiple, matrix, and true false type questions with values 1-4 assigned to each respectively. To dynamically load the appropriate question type based on user selection, I am using AJAX w ...

The scrolltop function is dysfunctional on CentOS operating systems

I'm currently working on implementing smooth scrolling functionality when a button is clicked. The feature works perfectly fine with a local Apache server and IE10+, but when the project is deployed on "CentOS", it doesn't work on the same browse ...

Margin of Google Pie Chart division

Struggling to eliminate a mysterious margin from a div generated by Google Charts, despite no defined margins in the code that could be causing it. Below is a visual representation of the problematic div: div with unidentified margin Any assistance on t ...

using jquery to retrieve the current time and compare it

This is the code I currently have: var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() var hours = currentTime.getHours() var minutes = currentTime.getMinutes() aler ...

What is the best way to sort a table by column index using HTML?

I find myself in a situation where I am not well-versed in HTML, Javascript, and CSS. Here is the scenario: <div class="table"> <table class="display-table"> <thead> <tr> ...

Strange behavior observed with CSS intellisense in Visual Code

While working on a ReactJS project, I noticed that when I opt for the style Jsx Attribute for inline CSS, . CSS intellisense seems to not work or only work after I manually add some fields. However, if I manually type the style attribute without using t ...

The Express.js feature "app.use() mandates the use of middleware functions"

Currently, I am delving into learning Express.js 4 and Node, but I seem to have hit a roadblock with an error that has me stumped. I'm attempting to utilize the node-sass package to compile my sass code; however, I've encountered obstacles in ge ...

The AJAX call was successful, however, the response did not contain any data

I have a MySQL table where I use a FOR EACH loop to display data on my page. I then make an AJAX request to update the displayed data every time a new row is inserted into the database. Although the AJAX request is successful, it returns empty data. I&apo ...

Querying MongoDB with Mongoose to find objects in an array based on a specific date stored

I am currently working on constructing a mongoose query to retrieve records that match a specific date. It seems like the query is functioning properly, but I'm not getting any results displayed because the date stored in my array of objects is a stri ...

The data that was received on the Express backend appears to have been altered from how it was originally sent from the React frontend

I am facing an issue while attempting to send a post request from my React front end to my Express back end. The object I am trying to receive is showing up as the key of another object with an empty string value. Below is my onSubmit React function: han ...

Is it possible to utilize target="blank" in an external link when working with MDX?

For my latest project, I am developing a blog using NextJS and MDX. One of the features I would like to implement is opening external links in a new tab by adding a target="_blank" attribute. In typical Markdown syntax, I usually achieve this by using [wo ...

"Can you tell me the method for obtaining an array within an Angular

Within the realm of PHP, there exist certain elements within an array: $this->data['messages']['ms'][] = 'Line1'; $this->data['messages']['ms'][] = 'Line2'; along with a method that return ...

Error caught: Unexpected token ''<' encountered while utilizing Next Middleware

My middleware setup is quite simple. It checks if the user is logged in using a boolean from the Zustand store, and then redirects the user to the login page accordingly. I followed the guidelines provided in the official documentation. import { NextRes ...

Raycasting in Three.js is ineffective on an object in motion

Working on a project that combines three.js and typescript, I encountered an issue while attempting to color a sphere by raycasting to it. The problem arises when the object moves - the raycast doesn't seem to acknowledge the new position of the objec ...

When the page is refreshed, the value bounces back and forth between

I've encountered a strange issue on my page with 6 textboxes. Whenever I enter values into these text boxes and then refresh the page, the values seem to jump to the next textbox (the one after the next). For example, if I enter values as follows: [ ...

The error "localStorage is not defined when using an axios interceptor in NextJS"

Within my root directory, there lies a file named api.js. This particular file is responsible for managing calls to an external API, with a focus on request and response interceptors. One specific use case involves injecting the access_token, leading to th ...

Having difficulty styling scrollbars using CSS

There is currently a scrollbar displaying over part of my page when necessary. https://i.stack.imgur.com/48Rbx.png I want to change the styling of the scrollbar to make it less bright and have a transparent background. I attempted to apply some styles, bu ...

Managing multiple Socket.io connections upon page reload

I am currently developing a real-time application and utilizing Socket.io for its functionality. At the moment, my setup involves receiving user-posted messages through the socket server, saving this data to a MySQL database via the controller, and then b ...