Ways to automatically adjust the margins of my HTML body page

I'm currently working on a school project to develop a website. The challenge I'm facing is customizing the navbar and header background colors in such a way that they extend seamlessly to the end of the page. Despite my efforts, there seems to be an issue where the headers' background colors (white and gray) don't reach the edge, leaving a visible blue background. I have included a screenshot to illustrate this problem along with my code:

<body>
    <div class="Headers">
        <h1 style="margin-bottom:0px;">
            COMPUTER GAMES REVIEW BY ASAF DAMTI
        </h1>
        <h2 id="secondheader">
            Welcome to my site
        </h2>
    </div>
    <div class="Menu">
        <ul>
            <li>
                <a href="#">Home</a>
            </li>
            <li>
                <a href="#">Details</a>
            </li>
            <li>
                <a href="#">On Me</a>
            </li>
            <li>
                <div class="dropdown">
                    <button class="dropbtn">Links</button>
                    <div class="dropdown-content">
                        <a href="https://store.steampowered.com/app/730/CounterStrike_Global_Offensive/" target="_blank">Csgo</a>
                        <a href="https://www.roblox.com/home" target="_blank">Roblox</a>
                        <a href="https://www.minecraft.net/en-us" target="_blank">Minecraft</a>
                        <a href="https://playvalorant.com/en-us/" target="_blank">Valorant</a>
                    </div>
                </div>
            </li>
            <li>
            <a href="#">Contact me</a>
            </li>
        </ul>
    </div>
</body>
</html>

The HTML portion appears as follows while the corresponding CSS is detailed below:

body {
    background-color: darkcyan;
    font-family: Calibri;
}

.Headers{
    background-color:white;
}
#secondheader{
    margin-top:0px;
    margin-bottom:1px;
    opacity:50%;
}
.Menu{
    background-color:gray;
}
.Menu a{
    background-color:gray;
    font-size:20px;
    padding:4px;
    padding-right:15px;
    text-decoration:none;
    color:black;
}
.Menu a:visited{
    color:black;
}
.Menu a:hover{
    background-color:white;
}
.Menu ul{
    margin-top:0px;
    padding-left:0px;
}
.Menu li{
    display:inline;
    padding:5px;
}
.dropbtn {
    background-color: gray;
    border: none;
    font-size: 20px;
    padding: 5px;
    padding-right: 15px;
}
.dropdown {
    position: relative;
    display: inline-block;
   
}
.dropdown-content{
    display:none;
    position:absolute;
    background-color:white;
    min-width:160px;
    z-index:-1;
}
.dropdown-content a{
        color: black;
        padding: 5px;
        text-decoration: none;
        display: block;
}
.dropdown-content a:hover {
        background-color: #ddd;
}
.dropdown:hover .dropdown-content {
    display: block;
}
.dropdown:hover .dropbtn {
    background-color: white;
}

To visualize the issue more clearly, you can refer to this picture of the website.

Answer №1

Most major browsers typically have a default margin of 8px on all sides.

To eliminate the space in the header, it is necessary to override this margin CSS attribute.

body {
  margin: 0;
}

The h1 tag also has default styles for margin-top and margin-bottom, which need to be overridden.

<h1 style="margin-bottom:0px;margin-top: 0;">
  COMPUTER GAMES REVIEW BY ASAF DAMTI
</h1>

body {
  background-color: darkcyan;
  font-family: Calibri;
  margin: 0;
}

.Headers {
  background-color: white;
}

#secondheader {
  margin-top: 0px;
  margin-bottom: 1px;
  opacity: 50%;
}

.Menu {
  background-color: gray;
}

.Menu a {
  background-color: gray;
  font-size: 20px;
  padding: 4px;
  padding-right: 15px;
  text-decoration: none;
  color: black;
}

.Menu a:visited {
  color: black;
}

.Menu a:hover {
  background-color: white;
}

.Menu ul {
  margin-top: 0px;
  padding-left: 0px;
}

.Menu li {
  display: inline;
  padding: 5px;
}

.dropbtn {
  background-color: gray;
  border: none;
  font-size: 20px;
  padding: 5px;
  padding-right: 15px;
}

.dropdown {
  position: relative;
  display: inline-block;

}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
  z-index: -1;
}

.dropdown-content a {
  color: black;
  padding: 5px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {
  background-color: #ddd;
}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown:hover .dropbtn {
  background-color: white;
}
<body>
  <div class="Headers">
    <h1 style="margin-bottom:0px;margin-top: 0;">
      COMPUTER GAMES REVIEW BY ASAF DAMTI
    </h1>
    <h2 id="secondheader">
      Welcome to my site
    </h2>
  </div>
  <div class="Menu">
    <ul>
      <li>
        <a href="#">Home</a>
      </li>
      <li>
        <a href="#">Details</a>
      </li>
      <li>
        <a href="#">On Me</a>
      </li>
      <li>
        <div class="dropdown">
          <button class="dropbtn">Links</button>
          <div class="dropdown-content">
            <a href="https://store.steampowered.com/app/730/CounterStrike_Global_Offensive/" target="_blank">Csgo</a>
            <a href="https://www.roblox.com/home" target="_blank">Roblox</a>
            <a href="https://www.minecraft.net/en-us" target="_blank">Minecraft</a>
            <a href="https://playvalorant.com/en-us/" target="_blank">Valorant</a>
          </div>
        </div>
      </li>
      <li>
        <a href="#">Contact me</a>
      </li>
    </ul>
  </div>
</body>

Answer №2

Don't forget to include this in your design:

*
{
    padding: 0%;
    margin: 0%;
}

If you need further assistance, feel free to reach out! Wishing you a wonderful day :)

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

developing a fresh node within the jstree framework

Recently, I have been working on creating a node using crrm as shown below $("#TreeDiv").jstree("create", $("#somenode"), "inside", { "data":"new_node" }); This specific function is triggered by a wizard, enabling me to seamlessly create a new node withi ...

Implementing WordPress link pagination for displaying only the next and previous buttons

I'm new to WP and need some guidance. I want to display a list of images in a post, with the ability for users to click next and previous to cycle through them like separate pages. To split the post into multiple pages, I added this code: <!- ...

Python Flask login screen not showing error message

Currently, I'm in the process of developing a login screen that incorporates Bootstrap and utilizes jQuery keyframes shaking effect. The backend functionality is managed by Flask. However, I seem to be encountering an issue where the error message "Wr ...

Utilizing Bootstrap 4 to ensure the final DIV is vertically stacked and fills the remaining space in the container

Having trouble creating a responsive layout using Bootstrap 4? Specifically, when two divs wrap vertically on smaller devices, the top div pushes the lower div down, exceeding the parent container. I want the lower div to fit within the container. How can ...

Can an HTML element have a dynamic scrollbar?

Is it possible to create a dynamic scrollbar with primefaces p:panel? Whenever I add the div, the scrollbar appears fixed on the page. How can I make this div position itself according to the user's browser, specifically within a p:panel? ...

Ensuring the validity of a signed cookie in Node using Express

I'm currently working on incorporating signed cookies in Node's express module. I've reviewed the documentation, but I'm struggling to understand how to properly verify them. My understanding is that verification must occur on the serve ...

Click the button to dynamically add a Bootstrap select element

I need assistance creating a select element with a Bootstrap class using a button click event. The element is successfully inserted into the body, but it does not appear on the page. https://i.sstatic.net/ppHfL.png <html> <head> <link re ...

What could be causing the divs to overlap? Without the use of floats or absolute positioning,

When resizing vertically on mobile, my date-time-container is overlapping the upper elements welcome and weather. Despite setting them as block level elements, adding clear: both, and not using absolute positioning or floats, the overlap issue persists. An ...

Challenges encountered while constructing a flexbox layout

I have a flexbox design that I am trying to create with the specific layout shown in the image: https://i.sstatic.net/Sy20K.jpg My HTML code is as follows (and I do not want to make any changes to it): <div class="wrapper"> <div class="page-h ...

What is the process for modifying a Joomla plugin?

Just starting out with Joomla development and recently installed Joomla 2.5 on my local computer for some practice. I have a question about editing Joomla plugins - specifically the layout of the Content - Pagebreak plugin (the pagination that appears wh ...

Issue with spacing in Internet Explorer 8

I am encountering an issue with a button style in IE8 that is adding extra space. I suspect it may be related to the min-height property, but I have tried using overflow hidden and min-height hacks without any success. Here is the link to the code on JSFi ...

Issue with displaying jQuery 3.5.1 mobile CSS formatting on live server preview using Visual Studio Code

Despite my best efforts, I can't seem to make the jQuery CSS stylesheet work properly. I've been using the live preview extension in VSCode and got the CSS directly from the jQuery website. <!DOCTYPE html> <html> <head> < ...

Tips for verifying the presence of a 3D model from Spline API within the DOM using Next.js

I am in the process of developing a brand new website and I have integrated a 3D model from spline, although it is taking quite some time to load. To improve user experience, I decided to implement a loader/Spinner. However, I'm facing the challenge o ...

Tips for Aligning h5 Headings with Unordered Lists

My footer contains the following code: HTML: <div class="container"> <div class="row"> <div class="col-md-6"> <div class="pull-right"> <h5><u><i>Information</i></u> ...

Submitting the form may cause disruptions for others

I currently have an email subscription form for my newsletter that is managed through PHP. This form appears in the footer of every page on my website. Check out a demonstration on JSFIDDLE While the form itself functions properly, I am encountering issu ...

Is it feasible to verify for vacant dates with a single click?

Is there a way to determine if a date value is empty, and if it is, display a popup indicating so? After some research, I stumbled upon a similar issue where the date value was always filled with a default "mm/dd/yyyy" value. The solution provided involv ...

What could be causing my page div to continuously expand on ios devices only?

I'm facing a strange issue where the div element in my document keeps growing endlessly. This problem has been observed on iPhone with iOS 5.1 and 6. It's fascinating to watch the height and min-height values of the page increase continuously, ca ...

How do I prevent a media query written for small screens from also affecting large screens?

@media only screen and (min-width: 320px), (min-width: 360px), (min-width: 375px), (min-width: 600px){ CSS properties for various screen widths are defined here } ...

Encountering a problem with loading the stylesheet

I keep encountering a 404 error when trying to load the CSS in my web application. The HTML content looks like this: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>PSL Inter App</title> <meta nam ...

Create a screen divided into two separate sections using horizontal split dividers

Trying to figure out how to set a div in HTML and then have a second div take up the remaining space. It seems like it should be simple, but I'm struggling with it. I'd like to have a div with a fixed height and then have another div take up the ...