What causes the right side of the header to extend off the screen at 100% width, while the left side doesn't even reach the edge of the screen?

My goal is to have the header span from one side of the screen to the other and stop exactly at the edges, but it currently extends beyond and goes off the screen. I was under the impression that setting a specific width would make it start from one edge of the screen and end at the other edge.

body{
    background-color: white;
    width: 100%;
}

header{
    width: 100%;
    background-color: #0000CD;

}

nav{
    display: flex;
    justify-content: center;


}

ul.main-menu{
    display: flex;
    width: 100%;
    justify-content: space-around;
    list-style: none;
}

li.menu-item{



}




<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Why OneDrive?</title>
    <link rel="stylesheet" href="../CSS/styles.css">
    <script src="../JS/3picslideshow.js" type="text/javascript" charset="utf-8" async defer></script>
</head>
<body>
    <header>
        <nav>
            <ul class="main-menu">
                <li class="menu-item">Home</li>
                <li class="menu-item">Usage</li>
                <li class="menu-item">About</li>
                <li class="menu-item">Acknowledgments</li>
            </ul> 
        </nav>
    </header>


</body>
</html> 

Answer №1

Try deleting the width: 100%; line from the body class as it is unnecessary. This should resolve the problem you are experiencing.

Answer №2

The body element comes with a default margin which can be removed by applying the following code:

html, body {
  margin: 0;
}

This will ensure that a 100% wide element fits perfectly within the width. Here's an example:

body {
  margin: 0;
}

.x {
  width: 100%;
  background: #fa0;
}
<div class="x">This is the DIV with class "x"</div>

Answer №3

Have you considered eliminating the width: 100% property from your body element? It might resolve the issue.

You can view an example here.

Answer №4

Eliminate the body's margin.

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

Is there a way to create a dynamic CSS for a custom JSF component through code generation?

I am currently developing a custom JSF component that displays content in multiple columns in a "responsive" manner. This component utilizes the "CSS Multi-column Layout Module" (http://www.w3.org/TR/css3-multicol/) (tutorial available in French: ). Belo ...

Background images are not appearing in Rails production environment

There seems to be an issue with my images not showing up in the production environment (link here). Here is a snippet of my code: _header.html.erb <%if action_name == 'index' %> <div class="main_header_bg" id="main_head ...

Implement a dialog on top of a current web page, achieve php-ajax query result, and enhance with

My website features 'dynamic' content, where 'static' nav-buttons replace specific div contents upon clicking. While I am able to retrieve my php/ajax results in a dialog box, I am struggling with placing this dialog above my current p ...

Using React.js to dynamically change a CSS class depending on a certain condition

I am trying to assign a CSS class to a div based on a specific condition. The issue I am facing is that it always takes the last condition. Below is the code snippet: When I run the code, I receive logos.length as 3 <div className= "${ (this.state. ...

Creating a CSS grid layout with an unspecified number of columns all set to equal width

Currently, I am in the process of designing a navigation bar using grids. In essence, when the user is an admin, there should be two additional links at the end of the bar. These links need to have the same width and should not be affected by the amount of ...

What is the method to display a caret in regular HTML text with the use of JavaScript?

Currently, I am studying JavaScript and aiming to develop a typing game similar to typeracer.com. The goal of the game is to type accurately and quickly without errors. In this game, users input text into a box, and JavaScript then compares their inputs w ...

The sticky positioning in Css does not function properly on mobile devices

Encountering a challenge with sticky CSS on Chrome. While viewing on mobile browsers, one element of the page fails to assume a sticky position. The issue is evident on this specific page When viewed from a computer, the code below works perfectly; howeve ...

Hugo is discussing the process of redirecting a list.html page to a single.html page

If your website URL is http://example.com and you have a section labeled updates, with links like http://example.com/updates/update1 and http://example.com/updates/update2 update1.md file can be found at content/updates/update1.md update2.md file can be ...

Is it possible for an HTML checkbox value to store a boolean rather than a string?

Strings are held by HTML Input values. For instance: This stores the string "yes". <input type="checkbox" name="checkThis" value="yes"> Nevertheless, for checkboxes it is sometimes beneficial if the value was a boolea ...

When I click on the button, the output does not appear

Even though I know how to write this in pure javascript, I am new to angular so when I click submit, nothing happens and I don't get any result. index.html <input type="text" ng-model="username" placeholder="Username"> <input type=" ...

Utilizing Ajax Blob URL for Audio Streaming

My goal is to retrieve audio data using an Ajax request and load it into an audio element. However, I'm running into an issue where the player does not seem to work properly. The play button remains disabled as if nothing has been loaded. Below is a s ...

Can javascript be used to swap out the folder in my URL?

I have been searching for solutions on how to change the language of my website using jQuery, but so far I have not found anything that works for me. Let's take my website as an example: www.domain.com I have separate folders for different languages. ...

Is there a way to trigger both the link and the div element simultaneously?

Is there a way to make both the button and the link light up simultaneously when hovering over the div element, instead of just the button lighting up first? <div id="b1"; class = b> <a href="test.html">BUY</a> < ...

Django template receiving incomplete data from view: missing variables

I am really confused by this one, any help on the subject would be highly appreciated. This is how I have written my code: @login_required def product(request, prod_id): pr ...

The jQuery window.load() function fails to execute on iOS5 devices

I added a basic loading div to my website that fades out once the entire page has finished loading. The code I used is simple: $(window).load(function(){ $('#loading').fadeOut(500); }); While this works well on all desktop browsers and Chro ...

Tips for positioning the search form in the navbar header

My brand image and list with 2 glyph-icons & a search form in the navbar header are not aligning properly. The search form button keeps dropping to the line below. Does anyone know a CSS trick to keep it on the same line as the rest of the links? All the ...

socket.io not defined and rejecting the connection

https://i.sstatic.net/B4bqV.pnghttps://i.sstatic.net/QfJqv.pngMy current code utilizes socket.io to display a message. However, when I execute node server.js, none of the output messages are being logged to the console. Below are snippets of my chat.html, ...

Is it possible to apply styling to a label and use it as a regular element?

I've come up with a unique way to create an accordion viewer using input and label elements. In order to vertically center my elements, I treat the label as if it were a div by giving it display: table and inserting a div inside of it. Here's wh ...

The element positioned with a z-index of -1 will be placed beneath the grandparent's division

Why does using z-index:-1 on an absolutely positioned child element make it go under the grandparent div? How can I ensure that the absolute-child stays under the parent div instead? .grandparent{ background:rgba(0, 128, 0, 0.89); width:500px; } .p ...

Is there a way to horizontally align a container in spite of screen space being occupied by other elements?

My dilemma involves a vertical sidebar navigation menu positioned on the left side, with dimensions of 211px width and 300px height. The main container is set to be 960px wide. When I attempt to center the container using margin: 0 auto;, it overlaps with ...