Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Float not working as expected

I have a navigation box, and the "Contact" element isn't fully right justified despite float being set to right.

<div id="navwrapper">
    <ul>
        <li class="single">Home</li>
        <li class="double" id="left">About</li>
        <li class="double" id="right">Contact</li>
        <li class="single">Book</li>
    </ul>
</div>

And the CSS

#right {
    float:right;
}

Other questions seem to suggest swapping the left and right elements over to get the desired effect, but that didn't work.

jsFiddle

like image 574
cjm Avatar asked Mar 05 '26 12:03

cjm


2 Answers

You were missing overflow:hidden on your ul element.

Check this working jsFiddle.

overflow:hidden is recommended on the parent of floating elements. It forces the parent to wrap around all of them, thus preventing weird behaviour as you were experiencing..

like image 127
Yotam Omer Avatar answered Mar 08 '26 19:03

Yotam Omer


I belive you are searching for margin but in minus position, for example:

#right {
float: right;
margin: 0 -3px 0;
}

That will fix your issue

Fiddle: http://jsfiddle.net/TQFzS/4/

like image 35
copypaste Avatar answered Mar 08 '26 19:03

copypaste



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!