tags:

views:

47

answers:

3

I'm using a css unordered list to make a site navigation bar, using display: inline, display: block, and float: left. The next element that I put after the navigation bar is placed to the right of it. How can I align the next element so that it is displayed below?

The html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"&gt;

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/test.css" />
  </head>

  <body>
    <div>
      <ul class="nav">
        <li class="nav"><a class="nav" href="#">One1</a></li>
        <li class="nav"><a class="nav" href="#">Two</a></li>
        <li class="nav"><a class="nav" href="#">Three</a></li>
        <li class="nav"><a class="nav" href="#">Four</a></li>
      </ul>
    </div>

    <div><h2>Heading</h2></div>
  </body>
</html>

The css:

ul.nav, ul li.nav {
  display: inline;
  margin: 0px;
  padding: 0px;
}

ul.nav {
  list-style-type: none;
}

li.nav {
  display: block;
  float: left;
  background-color: red;
}

a.nav {
  background-color: green;
  padding: 10px;
  margin: 0px;
}

a:hover.nav {
  background-color: gray;
}
+2  A: 

Try using clear: left; on the div after your list. This should then clear the element to appear below your unordered list.

Edit: should actually read clear: left; although using clear: both; will also work

simnom
A: 

Use clear:left; on the div after your list

or simply remove float:left; from li.nav

Samuel
A: 

Use a float clear and then size and position the heading div below it. If you give it a width larger than the space to the right of the nav bar, it should automatically drop down.

CSS:

.clear { clear:both; }
#heading { position:relative; margin:0px auto; width:980px; }

HTML after nav:

<div class="clear"></div>    
<div id="heading">Heading</div>
staypuftman