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

Conceal the Standard Select Dropdown Arrow in Internet Explorer 9

VIEW DEMO I attempted to use the CSS property appearance: none; to hide the select dropdown arrow, but it still shows in IE9. Refer to the image for clarification. Does anyone have a solution to hide the arrow using either CSS or jQuery? Below is my cod ...

Best Practices for Implementing an Autocomplete Search Box in HTML

I'm currently working on implementing the code below and I could really use some guidance. Despite reading and watching Google Developers' YouTube videos, I am still struggling as I am new to this. My main goal is to integrate an autocomplete sea ...

Updating Sencha list itemTpl on the fly

Is there a way to dynamically change the itemTpl in a Sencha list to adjust the visibility of a column based on certain conditions? Your assistance would be greatly appreciated. ...

Can you have two onclick events triggered by a single Div? (ASP.NET / HTML)

I am currently working with Div's and facing a challenge of handling 2 events with just one Div-Click.. I wanted to use both onclick="" and OnClientClick, but it seems that when using a Div, I cannot make use of OnClientClick. Can anyone provide me ...

Discover the method for measuring the size of a dynamically generated list

I'm currently working on a chat box that displays messages as a list. One issue I'm facing is that when I click on the start chat button, the chat box opens but the length of the list always remains zero. How can I resolve this problem? $(docu ...

Angular animation not firing on exit

I am encountering an issue with my tooltip component's animations. The ":enter" animation is working as expected, but the ":leave" animation never seems to trigger. For reference, here is a link to stackblitz: https://stackblitz.com/edit/building-too ...

Automatically updating database with Ajax post submission

I have customized the code found at this link (http://www.w3schools.com/PHP/php_ajax_database.asp) to update and display my database when an input box is filled out and a button is clicked to submit. Below is the modified code: <form method="post" acti ...

What is the best way to eliminate the space between the website's border and the image?

Is there a way to eliminate the space between the left and right borders? I want the picture to fill 100% of the browser window. https://i.stack.imgur.com/gqgOs.png img.test { display: block; outline: 0px; padding: 0px; margin: 0px; } <img c ...

Encountering a problem with Selenium when dealing with tabular data displayed in a DIV format on a website, where each row is encapsulated within its own DIV element

While creating Selenium automation tests for a website with multiple rows contained within a main DIV element, each row represented by a separate DIV. For example, if there are 5 dynamically generated rows, the HTML code structure would look like this: < ...

Efficiently repositioning Kendo Mobile Buttongroup to a new row as needed

In my current project, there is a specific requirement to display three button groups in a row. If there are more than three buttons, they should move to the next row dynamically as the data will be fetched from the server. For reference, below is a sampl ...

Windows Outlook - automatic tag wrapping feature

My goal is to ensure that buttons wrap properly inside their cell. I have set a max-width for the cell as well as a ghost table of 200px. The width should not extend past 200px, causing the span to wrap to the second row automatically. This method works ev ...

What is the best way to line up a number and text using CSS?

Creating a basic gauge meter with min value 0 and max value 2. The current UI progress is as follows: .sc-gauge { width:200px; height:200px; margin:200px auto; } .sc-background { position:relative; height:100px; margin-bottom:10px; background-color:g ...

JavaScript form button press tracker

Hello! I've been tackling a challenge involving a JavaScript function to count button clicks. The catch is, the button type is set to submit, causing the page to reload every time I click it. Below is the snippet of code that contains the problemati ...

Tips for displaying an image that is embedded within a CSS file

I discovered an interesting background image embedded in a CSS file. Is there a way for me to actually view it? "iVBOR..." to "5CYII=" and saved it in a file named image.png - unfortunately, this method did not yield the desired outcome.

...

I require assistance in troubleshooting and repairing my HTML and JavaScript code

I am working on creating a feature where users can input their upcoming birthday date and receive an alert showing how many days are left until then. However, I encountered an issue where the alert displays NaN (Not a Number) before the birthday is entered ...

Possible revised text: "Exploring methods for verifying elements within a div using Selenium

I have a situation where I need to verify elements within a div by using the following xpaths. The xpath for each item is as follows: Item 1:- //*[@id='huc-last-upsell-rows']/div[1]/div[2]/div[1]/div/div/a/img Item 2:- //*[@id='huc-last-u ...

Updating the hyperlink of an html element using css

I am looking to update this A tag <a href="contact.html" >Contact</a> to <a href="tel:+13174562564" >Contact</a> using only CSS, if possible. Alternatively, like this <a href="tel:+13174562564" >+13174562564</a> ...

What is the process for setting up a bootstrap grid with a single column at the top and two columns

Can anyone help me figure out how to rearrange a bootstrap grid from three columns on desktop to one column above and two below on mobile? I've attempted multiple methods, but haven't had any luck... https://i.stack.imgur.com/oY2VU.png ...

Ensure each list item is directly aligned when swiping on a mobile device

Looking to make a simple horizontal list swipeable on mobile devices with tabs that snap from tab to tab, activating the content for the active tab immediately. The desired effect is to swipe directly from one tab to the next without having to click separ ...

The nb-install mixin is not recognized

While working with angular5, I encountered the 'No mixin named nb-install' error when running npm start or serve Module build failed: undefined ^ No mixin named nb-install Backtrace: stdin:13 in E:\mrb_bugfixes& ...