Although achieving what you're looking for is possible, in my opinion, finding an elegant solution using current CSS is quite challenging. Here's a workaround that partially addresses the issue.
In order for the list to be responsive to the size of the floated element adjacent to it, both elements must be enclosed within the same container:
<div id="container">
<ul class="menu">
…
<li>…</li>
</ul>
<div id="floated">…</div>
</div>
To ensure the container adjusts to the size of the floated element inside it, the container also needs to float:
#container {
float: left;
}
To prevent the next sibling element from floating alongside the container (unless cleared with the clear
property set to left
or both
), a clear fix may be required after it:
<div id="container">
…
</div>
<div style="clear: both; width: 0; height: 0; line-height: 0"><!-- for MSHTML --></div>
<!-- insert next sibling here -->
To align the lower boundary of the list item with the bottom of the floated element, the list item should be positioned absolutely:
ul.menu li:last-child {
position: absolute;
bottom: 0;
}
Furthermore, the container should have relative positioning to ensure the bottom: 0
of the li
element aligns accurately with the bottom of the floated element:
#container {
position: relative;
float: left;
}
If precise coordinates are required for the last list item, considering the total space occupied by preceding items might offer a solution:
ul.menu li:last {
position: absolute;
/* your specific case */
left: 0;
/*
* Assuming: 3 items above, each with a computed height of 1em, no margins in between.
*/
top: 3em;
bottom: 0;
}
Ensure the ul
element is not positioned to maintain accurate li
placement details.
In conclusion, the necessary CSS styling would entail:
#container {
position: relative;
float: left;
}
/* As per your original code */
#container #floated {
float: right;
}
#container ul.menu li:last-child {
position: absolute;
/* see above */
left: 0;
top: 3em;
bottom: 0;
}
And the corresponding HTML markup:
<div id="container">
<ul class="menu">
…
<li>…</li>
</ul>
<div id="floated">…</div>
</div>
<div style="clear: both; width: 0; height: 0; line-height: 0"><!-- for MSHTML --></div>
<!-- add next sibling content here -->
This method functions correctly in Chromium 22, yet it lacks aesthetics. Reflect on why stretching the last list item is imperative and perhaps consider alternative approaches, such as expanding the entire list layout instead.