What could be causing the overlap between my section and header on the website? Any suggestions on how to resolve

I've been working on my website and I'm having an issue with the header overlapping. I used float left for my navigation bar, but when I try to add a showcase below it, the showcase only overlaps the header section. The aim is to have a navigation bar at the top left with a dropdown menu, followed by a showcase that covers the rest of the screen. Any suggestions on how to fix this will be greatly appreciated :).

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>my website</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <header> 
        <div class="container">
            <nav>
                <ul>
                    <li><a href="index.html">Home</a></li>
                    <li><a href="about.html">About</a></li>
                    <li class="dropdown-link"><a href="#">list 1</a>
                        <ul>
                            <li class="dropdown-content"><a href="#">sublist 1</a></li>
                            <li class="dropdown-content"><a href="#">sublist 2</a></li>
                        </ul>
                    </li> 
                    <li class="dropdown-link"><a href="#">list 2</a>
                        <ul>
                            <li class="dropdown-content"><a href="#">sublist 1</a></li>
                            <li class="dropdown-content"><a href="#">sublist 2</a></li>
                        </ul>
                    </li>
                </ul>
            </nav>
        </div>           
    </header>

    <section>
        <h1> Hello World</h1>
    </section>
</body>
</html>

body {
    padding: 0;
    margin: 0;
}
.container {
    width: 100%;
    float: none;
}

ul {
    padding: 0;
    margin: 0;
    list-style: none;
}

ul li a {
    color: black;
    text-decoration: none;
}

header {
    width: 90%;
    margin: auto;
    display: block;
}

header ul li {
    float: left;
    padding: 10px;
}

.dropdown-content {
    float: none;
    padding: 5px 0 5px 0;
    display: none;
}

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

.showcase {
    display: block;
}

Answer №1

In my opinion, adding some height to the container class or adjusting the header (such as setting height:100px) would help. Alternatively, you could add some margin-bottom to create space and ensure the section tag is properly positioned. As a beginner myself, I often use border: 1px solid black to visually understand the dimensions of elements and make necessary adjustments (I used this technique with your container class).

Answer №2

One common issue you may encounter is the lack of a clearfix in your code, which is essential for resolving zero height problems when using floats. If you want to learn more about this topic, check out this link.

To address this issue, simply include the following CSS:

.clearfix:after {
  content: " ";
  visibility: hidden;
  display: block;
  height: 0;
  clear: both;
 }

Remember to assign the clearfix class to your container element like so:

<div class="container clearfix">

In addition, I suggest exploring Flexbox as a modern and effective alternative to float layouts. It offers great flexibility for aligning items in one direction and is much easier to use compared to traditional float methods.

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

HTML template without the use of server-side scripting languages like PHP or Ruby on

Is there a way to develop HTML templates without relying on backend languages such as PHP or Ruby on Rails? I tried using JavaScript, but I encountered issues with my current code when adding nodes after the DOM is loaded. An ideal solution for me would ...

Redis: Unable to establish a connection as net.connect is not recognized as a

I'm struggling to integrate Redis with nodejs Encountering issues during execution Despite using the same code, I am facing this error: Here's my code snippet: import { createClient } from 'redis' export const client = createClient({ ...

Failed to validate user profile because of an InternalOAuthError error while using passport-facebook-token to verify the token

In my iOS application, I am utilizing the Facebook API for user login and receiving an access token in return. Now, I need to use this token to verify a user on my backend server. For this purpose, I have implemented the passport-facebook-token strategy w ...

Having trouble fetching configuration values with Vue.js

console.log(process.env.test); displays "undefined" in the console. In the dev.env.js file, I have the following configuration. Do you see anything that I might have overlooked? 'use strict' const merge = require('webpack-merge') con ...

Enhancing User Experience with Bootstrap V5 Form Validation and Sweetalert2: Displaying a Message of Success Upon Successful Submission

I am currently working on implementing a simple form using Bootstrap 5 that includes validation. My goal is to display an alert message when the form field is successfully submitted using Sweetalert2. Below is the code I have: HTML <form action=&q ...

Struggling with adding icons to the home screen in a Create React App?

When working with the manifest.json file, various icon sizes are specified as shown in this example: { “src”:”images/icons/apple-icon-57x57.png”, “type”: “image/png”, “sizes”: “57x57”, } In the index.html file, the ...

Retrieve all references to child elements in React

I am working on a component that renders dynamic children, and I need to assign a unique ref to each child (e.g. ref={'childID' + index}) After the children have been loaded, I am looking for a way to loop through them and access their refs. Is ...

What is the method for altering the background color with JavaScript in CSS?

I need assistance with changing the background color using JavaScript. Specifically, I want to change the color of the background property that is located within .diagnosis-kit-inner .nav-tabs .nav-item.active:after. Can someone provide guidance on this? T ...

Incorporate JQuery into your NodeJS project by leveraging the existing minified file

Can we integrate JQuery into Node.js and make JQuery AJAX calls without altering the syntax by using a pre-downloaded minimized JQuery file? To clarify, I have the minified file and wish to incorporate it into Node.js in this manner: var jquery = require( ...

The alignment of two responsive divs is off

My goal is to create two responsive columns of divs that stack on top of each other as the screen size decreases. The challenge I am facing is getting these divs to always be centered and sit next to each other, using only inline CSS. <div id="containe ...

inactive toggle being released

I am facing an issue with my two slider menus, where only the right menu holds the active value when clicked. The left menu slides out only when the toggle button is held down, but I need it to slide out when the toggle is simply clicked and not held down. ...

While trying to set up a development server in Firebase, I mistakenly deleted my build folder

I recently encountered an issue with my Firebase project. While trying to set up a development server for my existing React web app that is already in production, I ran into some unexpected problems. firebase use bizzy-book-dev firebase init firebase ...

HTML5 pattern grouping feature is not functioning as expected

I am attempting to validate this regular expression pattern="([a-zA-Z]+[0-9]*){4,}", which essentially means: It must always start with an alphabetic character. If a number is included, there must be at least 4 characters in total; for example, aaaa would ...

JavaScript comparing variables to nested object properties

items resembling this are heading my direction: var info = { a0: { name: 'lengthy title 0', var1_min: '10', var1_max: '99', select: ['alpha', 'gamma'], display: 'value0' }, b12: { ...

Is it recommended to make updates to your database using an Ajax call?

I encountered a situation where I need to update a database after an ajax call is completed. To retrieve the value for updating the database, a SOAP call (or server request) must be made, which takes some time. My goal is to utilize the value obtained from ...

Locate every JavaScript array available

I am in the process of converting a variable number of vector shapes into coordinates. Each shape's coordinates are stored within its own JavaScript array. For instance, the JavaScript code might be structured like this: var la0001 = [33,108,66,141, ...

Sending a value to CSS using a selector

Can CSS be instructed to implement a selector with a specific value that acts as a variable? For example: -- HTML -- <div class-name="div-3"></div> -- CSS -- .div-(x) { width: 100px * x; } ...

Having trouble figuring out why Ajax is sending Null to my .net core MVC controller

Learning Ajax and jQuery has been quite a challenge for me as a beginner. My current task involves passing an object with two string arrays - one for search parameters, the other for search values. The problem arises when I click the submit button and th ...

Issue with ESLint: Unexpected token found in JavaScript when converting to a dictionary

I've implemented a JavaScript code snippet that loops through an array of fields to find specific properties and then adds them to a dictionary. For another example, you can check out this site. return this.getFields() .reduce((mappings, field) =& ...

Having trouble retrieving data with the componentDidMount API call in React?

I'm currently in the process of building a Gallery feature. Initially, I hardcoded the image links, but now I want to fetch them using an API call. The implementation didn't go as planned, and it's still pulling the hardcoded images from the ...