What is causing the navigation to disappear off the left side of the screen when the media query is activated?

When the screen size is less than 450px, the logo disappears in order to make room for navigation. However, the navigation then extends about 20px off the left side of the screen.

View the code here

This CSS code snippet appears to be relevant:

@media screen and (max-width: 450px) {
    img#logo {
    display: none;
    width: 0;
    }
    nav {
    width: 100%;
    min-width: 100%;
    }
}
div#top{
        position: fixed;
        top: 0px;
        width: 100%;
        height: 130px;
        z-index: 5;

}
img#logo {
        border: 0;
        float: left;    
        width: 20%;
        margin-right: 2%;
        margin-left: 2%;
        margin-top: 5px;
        max-width: 123px;
        }


nav {       position: fixed;
            top: 0px;
            right: 0px;
            width: 70%;
            float: right;
            padding: 2%;
            height: 60px;
            max-height: 60px;
            margin: 5px 5px;
            }
nav button {
            padding: 0 4px;
            height: 28px;
            font: 16px;
}

nav button ul {
            position: relative;
            display: none;
}

nav button:hover ul, nav button:focus ul {
            display: block;
            z-index: 6;
            list-style: none;
            padding: 4px;
}

nav button:hover li, nav button:focus li {
            padding: 4px;
}
nav a {
        text-decoration: none;
        color: white;
}
nav a:hover, nav a:focus {
            color: #9dab71;
}

The following HTML code seems to be relevant:

<div id="top">
<a href="default.html"><img id="logo" src="http://www.briligg.com/images/briligg-loopless-blue.png" 
alt="briligg home" /></a>
<nav>
<button><a href="futuremoon.html#begin">Purpose</a></button>
<button><a href="moonvsmars.html">Moon vs Mars</a>
   <ul>
     <li><a href="moonvsmars.html#ambiance">Ambiance</a></li>
     <li><a style="border-bottom: 1px solid #666666;" href="moonvsmars.html#communication">Communication</a></li>
     <li><a href="thereandback.html">There and Back</a></li>
</ul>
</button>
<button><a href="beingthere.html">Being There</a>
<ul>
        <li><a href="beingthere.html#domination">World Domination</a></li>
        <li><a href="beingthere.html#chickens">Chickens</a></li>
        <li><a href="beingthere.html#gravity">Down with Gravity</a></li>
        <li><a href="beingthere.html#moonstar">The Moonstar</a></li>
        </ul>
</button>
</nav>
</div>

Answer №1

When setting the min-width of the nav element to 100%, it can cause issues with padding and margin making the element wider than the viewport due to the box model.

To resolve this, simply add box-sizing: border-box; to your nav element. This will ensure that any padding or border is included as part of the width. For more information, you can visit this link.

I recommend brushing up on how the box model functions by checking out resources like w3schools and adjusting your padding and margin as needed.

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

Selenium VBA - Issue with checking checkbox

I'm currently working with a spreadsheet that is extracting data from a website. One aspect of my project involves checking a tick box. Although I can easily locate the element using FindElementbyCSS, clicking it doesn't actually select the tick ...

The text that follows the cursor seems to stand out taller than the rest

When I type words in a textarea input field, the cursor seems to be taller than it should be (as shown below). What is causing this issue and is there a way to make it as tall as the words with a font size of 38px? Here is the code snippet: <textarea n ...

Safari browser is experiencing issues with CSS positioning

I am currently working on a website where I am using CSS to position a specific element on the page. The element is absolutely positioned and contained within a relatively positioned parent element. While it displays correctly in Firefox and IE, there seem ...

Angular 4 Form remains valid even when an incorrect value is entered

Within my Angular 4 project, I encounter the issue of controlling input fields in multiple forms. Specifically, I need a mechanism to disable the save button if the input value is incorrect. For example, when I require an input field to only accept positi ...

Tips for troubleshooting ImageArray loading issues in AngularJS

Having some trouble learning Angular and getting stuck with this Image array. Can someone please help me understand what's wrong with my code and how to fix it? FilterAndImages.html <!DOCTYPE html> <html ng-app="store"> <head> < ...

What steps should be taken to acquire the most recent CSS files for a theme?

We are facing an issue with implementing a versioning system for our CSS files. Currently, we append a build number to the CSS link programmatically (e.g. \themes\ssss\abc.css?1011) so that clients always receive the latest CSS files with ea ...

Step by step guide to implementing form step validation in a multi-step jQuery form with radio buttons

I have implemented the sample code provided in this link, with the addition of 2 extra form steps: LINK TO SAMPLE FORM My form consists of radio buttons (2 per page) instead of text boxes. How can I ensure that each form page is validated so that the for ...

Using the power of Javascript's jQuery library: the fantastic ".on()" Event Handler

I'm encountering an issue with the Jquery Event Handler ".on()". On my home page, I have a Favorite button on each post. If the post has not been favorited: li appears inactive Event 1 is triggered If the post has been favorited: li appears act ...

Paste the URL into your clipboard without relying on JavaScript

Is there a way to implement a copy to clipboard function for email templates without relying on JavaScript? ...

Submit Button Not Responding on Mobile Device

I am facing an issue with my VueJs app. The contact form works perfectly on browsers, but when accessed from a smartphone or tablet, it fails to function properly. I have tried two different implementations to resolve the problem. Here is the first implem ...

Ways to expand the border horizontally using CSS animation from the middle

Currently, I am experimenting with CSS animation and I have a query regarding creating a vertical line that automatically grows in length when the page is loaded. I am interested in making the vertical line expand from the center in both upward and downwar ...

Can a background image be displayed within a DIV using position:absolute?

I have scoured every corner, yet the answer still eludes me. In my style sheet, I have a DIV with absolute positioning and a background image. Within that DIV, I want to place a paragraph that appears underneath the background. I attempted to use z-inde ...

Steps to toggle the visibility of a table by clicking on a plus or minus button

//Custom Table Display Script using JQuery $(document).ready(function(){ $('.table1').on('click',function(){ $('.table1shw').show(); }); }); //A ...

What is the process for incorporating the !important declaration into a CSS-in-JS (JSS) class attribute?

I'm currently exploring the use of CSS-in-JS classes from this specific response in conjunction with a Material UI component within my React project. In order to override the CSS set by Bootstrap, I've decided to utilize the !important modifier. ...

Accepting PHP multidimensional array through ajax

My PHP code includes a script to open a database, fetch data, and encode it into JSON format. include_once($preUrl . "openDatabase.php"); $sql = 'SELECT * FROM dish'; $query = mysqli_query($con,$sql); $nRows = mysqli_num_rows($query); if($nRow ...

Methods for passing JavaScript variables to PHP

I have encountered this problem on Stack Overflow before, but I couldn't find a solution that worked for me. I am using Codeigniter and have a form where users can rate a product. What I need to achieve is to insert the user's rating into the dat ...

Arabic and Latin letters become intertwined

I am currently working on implementing an Arabic version of our website without affecting the other languages. The goal is to keep the changes to the markup minimal. Here is the English version: <div class="location_description"> <span itemscope ...

Identify a CSS style or attribute that is being dynamically assigned using JavaScript

While using the Jquery Cycle plugin for my slideshow, I'm looking to trigger an event when a specific slide is active. The Cycle plugin handles this by adjusting the opacity of images within a div in this manner: <div style="position: absolute; to ...

Utilizing jquery for displaying and hiding notifications - Notyfy in action

Recently, I've started working with jQuery and have come across the useful Notyfy jQuery plugin. My goal is to display a notification bar with specific messages based on certain conditions such as success or error. I'm trying to achieve somethin ...

- Customizing the width of each dropdown level in a unique way

Working on a customized menu design that you can view live at: Focusing on the third level menu, I encountered an issue where all menus have the same width due to sharing the dropdown-menu class. While I understand the root cause of the problem, I am unsu ...