0

I know it has something to do with the header ul li in css, but I'm not sure why it overlaps and how to fix it. I did float left for my navigation bar, but the section goes on top of that. html. The top left should have a navigation bar with a dropdown menu, and I'm trying to put a showcase under that which covers the rest of the screen. However, when i put the showcase in, it only overlaps the header. I'm confused any help will be 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>enter code here


body {
    padding: 0;
    margin: 0;
}

/* global */
.container {
    width: 100%;
    float: none;
}

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

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


/* header */

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 */
.showcase {
    display: block;
}
anon19740
  • 7
  • 3

2 Answers2

0

I think you should put some height to the container class or your header(try height:100px for example), or at least some margin-bottom so it "pushes" the section tag. As a noob myself, when i find myself in situations like this i put border: 1px solid black to things so i can see what are the dimentions of the elements and then fix them( i did that with your container class)

0

It's because you're lacking a clearfix, which is needed to fix a zero height issue when using floats. You can read more about it here.

Basically, you need to add this to your CSS:

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

And add the clearfix class to your container:

<div class="container clearfix">

While on the subject of float layout - I highly recommend learning Flexbox as a more modern solution. It's perfect for situations like this where you're trying to align items in a single direction. It is widely supported and much more user-friendly and powerful than float layouts.

somdev
  • 186
  • 1
  • 8