Reputation: 634
Why am i having a small space below my nav. i've set the margin of my nav to 0 and everything below it. still the space doesn't disappear. Here's my mark up.
<!DOCTYPE html>
<html>
<head>
<title>HTML5</title>
<style>
body{
width: 964px;
background-color: white;
margin: 0 auto;
border: 1px solid black;
font-family: sans-serif;
}
nav{
width: 964px;
background-color: blue;
margin: 0;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
}
nav ul li {
display: inline-block;
float: left;
}
nav ul li a{
display: inline-block;
padding: 10px;
text-decoration: none;
color: #fff;
background-color: blue;
}
nav ul li a:hover{
background-color: #00a;
}
header{
text-align: center;
background-color: orange;
}
header h1{
margin: 0;
padding: 20px;
}
aside{
float: left;
width: 180px;
height: 500px;
background-color: red;
}
aside ul{
list-style-type: none;
padding-left: 15px;
}
aside ul li a{
display: inline-block;
text-decoration: none;
background-color: #080;
padding: 5px;
width: 139px;
color: white;
border-bottom: 1px solid black;
}
aside ul li a:hover{
background-color: #050;
}
section{
height: 500px;
width: 964px;
background-color: green;
}
footer{
clear: both;
background-color: yellow;
text-align: center;
padding: 5px;
}
.clearfix:after{
content: " ";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix{
display: inline-block;
}
</style>
</head>
<body>
<header><h1>Header</h1></header>
<nav class="clearfix">
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">CONTACT</a></li>
<li><a href="#">ABOUT</a></li>
</ul>
</nav>
<aside>
<ul>
<li><a href="#">Champions</a></li>
<li><a href="#">Runes</a></li>
<li><a href="#">Skins</a></li>
<li><a href="#">Masteries</a></li>
</ul>
</aside>
<section></section>
<footer>footer</footer>
</body>
</html>
I just want to eliminate the space between the nav and the aside but Putting margin: 0 on every container near the nav is not working.
Upvotes: 0
Views: 82
Reputation:
:after
is a pseudo element which tells the browser to render a fake element inside the element after the content.
.clearfix:after{
content: "";
display: block;
clear: both;
}
This is a block element, which means that it takes the full width of it's parent. However, the following rule makes the pseudo element's parent .clearfix
into an inline-block element. This means that the element will only take up the mininum width that its content requires.
.clearfix{
display: inline-block;
}
You're seeing the space because inline-block elements are rendered inline as words, the white-space on either side of the element is rendered as a single space. You can solve this problem using either of the following methods.
Remove the inline-block rule
(Demo)
.clearfix{
display: inline-block;
}
Or, set the font size of the parent to 0, then set the font size for all direct children to the base font size.
(Demo)
body {
font-size: 0;
}
body > * {
font-size: 1rem;
}
Upvotes: 6
Reputation: 125
when you remove the following attribute it gets rid of the space...
.clearfix {
display: inline-block;
}
Upvotes: 1