I have a list:
<ul> <li>Number 1</li> <li>Number 2</li> <li>Number 3</li> ... </ul>
All the <li>
are floating. I need the height of the <ul>
box. If I remember correctly this is not valid:
<ul> <li>Number 1</li> <li>Number 2</li> <li>Number 3</li> ... <hr class="clear" /> </ul> .clear { clear: both; }
How can I do this? The number of items in the list can be different so I can't use fixed height.
How to I get the full height of the list as $(ul). height() just gives the height of the scroll viewport not the height of the full list. Things like Get The Full Height Of HTML Element That's Partially Hidden By Overflow:Hidden With JQuery / Javascript wont work as there is no inner wrapper, there is just the list.
The CSS float property controls the positioning and formatting of content on the page. Its most common use is to wrap text around images. However, you can use the float property to wrap any inline elements around a defined HTML element, including lists, paragraphs, divs, spans, tables, iframes, and blockquotes.
The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow (in contrast to absolute positioning).
Unordered lists ( UL ), ordered lists ( OL ), and list items ( LI )
Good options to contain the floats:
overflow: hidden
to the ul
.This isn't a direct answer to your question, but as an alternative could you consider using display:inline-block
? These days I just use that instead of float
where possible, as essentially most of the time it can achieve the same sort of objective without the total hassle of making containers properly contain inner floating elements and having to clear
them all the time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With