Struggling to eliminate the gap below my navigation bar

How do I remove the little space between my nav bar and main div, as well as the footer? I've tried adjusting margins, padding, and more, but nothing seems to work.

I've gone over the code multiple times and even searched on Google for a solution, but it's just confusing me further.

Since I'm new to coding, there's a high chance I may be making some silly mistakes :).

<!DOCTYPE html>

<html lang = "en" >

<head>

    <base href = "D:\workstation\my webpages\3rd day\" />
    <title>
    Home
    </title>
    <link rel = "stylesheet" type = "text/css" href= "style.css" />
</head>

<body >

<nav id = "top-menu" >
    <ul>
        <li><a href = "home.html">Home</a></li>
        <li><a href = "rock.html">Rock</a></li>
        <li><a href = "paper.html">Paper</a></li>
        <li><a href = "sci.html">Scissor</a></li>
        <li><a href = "contact.html">Contact</a></li>
        <li><a href = "buy.html">Buy</a></li>
    </ul>
</nav>

<div id = "maindiv" >

<header>
    <hgroup>
    <h1> Rock Paper Scissors Corporation </h1>
    <h2>Who Will Win!?</h2>
    </hgroup>
    <p>Oh, the suspense!</p>
</header>

<p class = "message" > Game status: Using HTML5 Drag and Drop</p>

<div class = "clear" ></div>
</div> <!-- main div ends here --> 

<footer class = "foot">
    <p>Copyright © 2017 Hamza waqar practice document</p>
</footer>

</body>

</html>







/*css starts from here*/

/*menu formating starts */

    body { 
        width : 100%;
        margin: 0;
        padding: 0;
        background-color : #a60;
    }
    nav#top-menu {
    width: 100%;
    height: 40px;
    background-color: #531;
    margin: 0;
    padding: 0;
}

    #top-menu ul {
    display: block;
    list-style-type: none;
    width: 600px;
    margin: 0 auto;
    padding: 0;
}
    #top-menu ul li a {
    display: block;
    float: left;
    max-height: 35px;
    width: 100px;
    margin: 0;
    padding: 5px 0;
    font-family: tahoma, sans-serif;
    font-size: 25px;
    text-align: center;
    background-color: #531;
    text-decoration: none;
    color: #da1;

}
    #top-menu ul li a:hover { border-bottom: 2px solid brown;}
/*menu ends*/

body, p {
    line-height: 1;
    font-family: Georgia, serif;
    font-size: 16pt;
}

h1, h2, h3, h4, h5, h6 {
    font-family: tahoma, sans-serif;
    color: #531;
    margin: .25ex 12pt;
}

h1 { font-size : 200% }
h2 {
    font-size: 130%;
    color: #840; }

    header p {
    font-family: tahoma, sans-serif;
    font-weight: bold;
    font-style: italic;
    font-size: 85%;
    margin: .25ex 12pt;
    color: #531;
        }

#maindiv {
    width: 900px;
    margin: 0 auto ;
    padding : 0;
    background-color: #eec;
}

p.message {
    width: 766px;
    margin: .5ex 0;
    font: normal 1em Tahoma, sans-serif;
    padding: 3px;
    background-color: #da1;
    color: black;
    margin-left : 20px;
    margin-top :20px;
}

section#rpsGame {
    margin: 1em;
}


.clear {
    margin: 0;
    padding: 0;
    clear: both;
}

footer.foot {
            width : 100%;
            margin : 0;
            padding :0;
            background-color : grey;
            height : 40px;
            width : 100%;

           }

footer.foot p {  color: #ccc;
    font-size: 70%;
    font-family: tahoma, sans-serif;
    text-align: center;
    margin: 0;
    padding: 10px 0;
}

Answer №1

Adjust the margin of your h1 element to 0 in order to resolve this problem

h1, h2, h3, h4, h5, h6 {
    font-family: tahoma, sans-serif;
    color: #531;
    margin: 0;
}

Answer №2

When it comes to HTML elements like <ul> and <p>, they will typically inherit margins from the browser by default unless specified otherwise. The extra space you may be noticing could be due to a margin being applied to the unordered list within your <nav>.

To address this issue, there are a couple of solutions you can consider.

One option is to include the following in your stylesheet:

#top-menu ul {
    margin: 0;
}

Alternatively, you can use a generic class that removes padding. Here's an example implementation:

<nav id="top-menu">
    <ul class="no-padding">
        <li><a href="home.html">Home</a></li>
        <li><a href="rock.html">Rock</a></li>
        <li><a href="paper.html">Paper</a></li>
        <li><a href="sci.html">Scissor</a></li>
        <li><a href="contact.html">Contact</a></li>
        <li><a href="buy.html">Buy</a></li>
    </ul>
</nav>

To ensure this class works as intended, you'll need to apply the following in your stylesheet:

.no-padding {
    padding: 0;
}

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

The Ng-include tag does not provide highlighting for its text

Within an ng-include template, I have a div that is not highlighting when hovered over. Although the cursor changes to a pointer when hovering over the text, attempting to click and drag to highlight it results in nothing happening. This issue is signific ...

Contrasting the addition of an onClick listener through Jquery versus utilizing an HTML onclick attribute

I found this interesting piece of code that I want to share with you all: <!DOCTYPE html> <html> <head> <script type="text/javascript" src="jquery-1.12.4.js"></script> <title> HelloWorld JQuery </t ...

Develop a program in Python using Selenium to automate web scraping in a loop

I am looking to create a loop that will allow me to extract the individual time figures for each horse in all eight races from the at the races website. Here is an example of the first race (17:15) out of the eight: from selenium import webdriver from s ...

Textarea with integrated checkbox

Can checkboxes be incorporated within a textarea using basic HTML and CSS? I'm aware that this can be achieved with tables, but I'm curious if it's possible within a textarea itself. ...

The stubborn HTML formatting that refuses to cooperate

Struggling with simple HTML formatting that just doesn't seem to be coming out right. Here is the code snippet in question: <div class="fc-event-time" data-hasqtip="true" aria-describedby="qtip-6"> 2:54 - 6:54 <i class="icos-refresh" styl ...

Utilizing the Bootstrap grid system to transform one row with two columns into two separate rows

I'm working on a grid layout that transitions like this https://i.sstatic.net/iU7mi.png When the width decreases, I want it to look like this https://i.sstatic.net/O5FAd.png This is what I have so far: .row > div { border: 1px solid black ...

The hamburger menu icon appears distorted when viewed on Safari browser

My website features a sticky hamburger menu on mobile. After testing it on iPhones and Android devices, I noticed that it looks slightly odd on iPhones. The left image shows how it appears on Android (LG G7 & G6), which is the desired appearance: The ...

I am looking to display multiple divs sequentially on a webpage using JavaScript

Looking to display a rotating set of alerts or news on my website. The goal is to show each news item for a certain number of seconds before moving on to the next one in line. However, I'm new to javascript and need help creating a code that will cont ...

Positioning elements to the right inside a Bootstrap 4 thumbnail behaves in a unique way when compared to Bootstrap

<div class='img-thumbnail'> <img src="a.jpg" class='img-fluid'> </div> This particular code snippet is from an HTML file using Bootstrap 4 CSS. It displays an image inside a styled box. Adding an h4 heading places ...

Changing the structure of divs by using elements from different divs

I'm looking for some help with adjusting the CSS of a div when hovering over certain elements. Here is my current code: <div class = "container-main"> <div class = "container-inner"> <ul class = "list"> &l ...

Trouble encountered when trying to use an anchor link with the .slideUp jQuery function

Would you be able to assist me with understanding why my anchor links are not functioning correctly? I have 3 anchor links, for example: Google (not working) Yahoo (not working) Facebook (working) Any insights on why Google and Yahoo are not working? &l ...

Strategies for Connecting CSS, JavaScript, and Image Files in Django

Being new to Django 1.9.5 and working on Windows, I am facing difficulty in linking my CSS, images, and JS files to the Django template. This is how my project structure looks like: Here is my settings page: BASE_DIR = os.path.dirname(os.path.dirn ...

Break apart PDFs into individual images or convert to HTML

I'm currently working on a project that requires the development of a unique webtool. The purpose of this tool is to allow users to effortlessly upload their PDF documents, which will then be displayed in a browser with an engaging page flip effect ut ...

Incorporate CSS styling into ScalaHelpers

Is it possible to customize the CSS for Scala Helpers and remove certain text from the textfield? https://i.sstatic.net/eG6HY.png @inputText(advForm("weeknr")) @inputText(advForm("jaar")) @inputText(advForm("datum")) --------------------EDIT 1---------- ...

What is the best way to reduce the font size on a

I've been applying the following CSS: .text_style3{ font:normal 8px Helvetica; color:#f7922c; } I'm trying to decrease the size further, but anything below 10px doesn't seem to work. I've attempted using 7px, 6px, 5px, etc., w ...

Troubleshooting complications with Bootstrap V5 Navbar including Nested Dropdowns (Submenu, Multilevel, Megamenu)

I'm currently working on implementing a Nested Navbar Dropdown (Submenu, Multilevel, and Mega Menu). However, I am encountering some challenges related to sizing with max-width and min-width, as well as handling directions with dropstart and dropend b ...

Utilize jQuery append() to create a grid layout using <td> tags

I need to integrate address information from an object into an HTML table using the append() method. The initial HTML table structure is as follows: <table class="shipping_information" border="1"> </table> To achieve this, I place the addre ...

Creating an image gallery with animated effects: A step-by-step guide

I am looking to develop a creative image gallery with animated effects. I also want to include panels and hyperlinks for each image, similar to the functionality on this website: http://www.microsoft.com/en-lk/default.aspx Can anyone guide me on how to ac ...

What could be causing my Angular JS application to malfunction?

Presenting myFirstAngularApp.html <html ng-app="store"><!-- The "ng-app" attribute initializes an Angular app. Everything inside this tag is considered part of the Angular app due to ng-app --> <head> <link rel="stylesheet" type= ...

The functionality of the tree-view feature in NodeJs is experiencing glitches

My attempt at creating a Tree-view has hit a snag. The collapse icon is not being displayed as expected. Here is the code snippet I tried: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-treeview/1.2.0/bootst ...