Solved

HTML Lists

Posted on 2016-11-11
3
48 Views
Last Modified: 2016-11-17
If I take out the "overflow:hidden", the page totally can't display. Any idea ?

<!DOCTYPE html>
<html>
<head>
<style>
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333333;
}

li {
    float: left;
}

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 16px;
    text-decoration: none;
}

li a:hover {
    background-color: #111111;
}
</style>
</head>
<body>

<ul>
  <li><a href="#home">Home</a></li>
  <li><a href="#news">News</a></li>
  <li><a href="#contact">Contact</a></li>
  <li><a href="#about">About</a></li>
</ul>

</body>
</html>

Open in new window

0
Comment
Question by:AXISHK
3 Comments
 
LVL 2

Assisted Solution

by:Amita Singh
Amita Singh earned 200 total points
ID: 41883488
replace ul css with this css
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    background-color: #333333;
    width: 100%;
    float: left;
}

Open in new window

0
 
LVL 54

Accepted Solution

by:
Julian Hansen earned 300 total points
ID: 41883496
That is because of the float left on the <li> items. The <ul> has no way of knowing what its height is. The overflow: hidden forces the <ul> to take on the height of the child elements.

First question - why is this a problem?

To get around it define your li as display: inline-block instead of float: left
li {
  display: inline-block;
}

Open in new window

1

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question