Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list based horizontal nav 1

Status
Not open for further replies.

jimmyshoes

Programmer
Jun 1, 2008
132
GB
I'm experimenting with list based navigation
I want to use a list to generate the following

1 2 3

I am using the following code

Code:
<style>
ul li{list-style:none;display:block;padding:10px;float:left}
</style>
<div style="border:1px solid #ffffff">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>

The problem is that the float:left is for some reason causing the list to be rendered below the surrounding bordered div

Why is this?
 
Hi

Oops, missed your question.
jimmyshoes said:
Why is this?
CSS 2.1 said:
The contents of floats are stacked as if floats generated new stacking contexts, except that any positioned elements and elements that actually create new stacking contexts take part in the float's parent stacking context. A float can overlap other boxes in the normal flow (e.g., when a normal flow box next to a float has negative margins). When this happens, floats are rendered in front of non-positioned in-flow blocks, but behind in-flow inlines.
In CSS 2.1 | Visual formatting model | Floats see the illustration below the quoted paragraph. Your [tt]div[/tt] is like their first [tt]p[/tt], but your has no visible un-floated content, so it collapses around the [tt]ul[/tt], which by itself has only its [tt]margin[/tt]s.

Feherke.
 
I have applied the fix as follows

Code:
<style>
ul li{list-style:none;display:block;padding:15px;float:left;}
</style>
<div style="border:1px solid #ffffff">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<div style="clear:both"></div>
</div>

The problem now is that the padding is uneven (there is more at the top)

Is there a fix to this?
 
Hi

That looks like in case of applying clearfix on the outer [tt]div[/tt]. That is why I suggested to use clearfix on the [tt]ul[/tt].

Going forward with your latest code, I would just remove the [tt]ul[/tt]'s [tt]margin[/tt]'s so it can pass "invisible" :
CSS:
ul [teal]{[/teal] [blue]margin:[/blue] [green]0[/green]; [teal]}[/teal]

Feherke.
 
That's fixed it!

Code:
<style>
ul { margin: 0; }
ul li{list-style:none;display:block;padding:15px;float:left;}
</style>
<div style="border:1px solid #ffffff">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<div style="clear:both"></div>
</div>

 
To add a footnote, my understanding of this problem is as follows:

a floated element is taken out of the normal flow of the page
So you need to add an empty div below your floated divs
The container div will then stretch to accomodate this empty div
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top