0

I'm trying to create navigation menu and I've added float: right; to my li tag in css, I also have div named .header which happens to be the background of the menu.

From some reason, when I add float the background just dissapears and when I removed the float the background has returned to his place.

body{
    margin: 0;
}

.header{
    width: 100%;
    height:  10%;
    background: #616161;
}
ul#nav{
    list-style: none;
}
ul#nav li{
    display: inline-block;
    padding-right: 25px;
    float: right;
}

HTML

<div class="header">
 <ul id="nav">
   <li><a href="#">Website</a></li>
   <li><a href="#">Home</a></li>
   <li><a href="#">test</a></li>
   <li><a href="#">test</a></li>
   <li><a href="#">test</a></li>
 </ul>
</div>

My code is pure, no css, no margin, only display that might be causing this problem of background positioning.

Is there a possibility to keep the text in right float and background together?

Before and after float using:

enter image description here

enter image description here

ExCluSiv3
  • 184
  • 2
  • 20

1 Answers1

1

before </ul> put this line DEMO

<div style="clear:both"></div>

it should work or add

.header {overflow:hidden;}

as suggested by @MaryMelody - DEMO 2

Anonymous
  • 10,002
  • 3
  • 23
  • 39
himanshu
  • 1,732
  • 1
  • 11
  • 12