tags:

views:

51

answers:

3

What CSS is needed to create such an HTML layout:

+--[li]---------------------------------------------+
|+--[div]-------------------------------------++---+|
|| A label with some text, truncate if necess…||BOX||
|+--------------------------------------------++---+|
|+--[div]------------------------------------------+|
|| Another label, truncate if necessary            ||
|+-------------------------------------------------+|
+---------------------------------------------------+
  • the outer <li> is fixed-width, floating left with the other list items in the list
  • the BOX should float to the right, above the upper <div>, it contains only two letters
  • none of the text in the <div>s should wrap, overflow should be hidden
  • the whole thing should work in IE7 quirks mode, preferably

Currently I have:

<li style="float: left; width: 175px; white-space: nowrap; overflow: hidden;">
  <div style="float: right;">XX</div>
  <div>A label with some text, truncate if necessary</div>
  <div>Another label, truncate if necessary</div>
</li>

But I can't get BOX to hover over the first label.

A: 

Did you try to float: left the first label?

BTW, Firebug will help you a lot in debugging...

Roberto Aloi
Changing nothing else `float: left;` does not make much of a difference I'm afraid.
Tomalak
+1  A: 

Is this the intended result?

alt text

<li style="float: left; width: 175px; white-space: nowrap; overflow: hidden;">
  <div style="float: right; position: relative; background-color: red;">BOX</div>
  <div>A label with some text, truncate if necessary</div>
  <div>Another label, truncate if necessary</div>
</li>

Omitting the position: relative, you would get:

alt text

Daniel Vassallo
In Standards Mode: yes, in Quirks Mode: no.
Tomalak
+1  A: 

This happens because right-floated div cannot float around nonwrappable text.

Try this

<li style="float: left; width: 175px; white-space: nowrap; overflow: hidden; position: relative;">
  <div style="position: absolute; right: 0px; background-color: #FFFFFF;">XX</div>
  <div>A label with some text, truncate if necessary</div>
  <div>Another label, truncate if necessary</div>
</li>

if this what you want.

Zenya
Absolute position brings the floated BOX out of its parent to the right border of the page.
Tomalak
It doesn't, because I added "position: relative;" into "li". I checked this in FF and IE8 - it works. Do you have different result?
Zenya
Nice, thank you very much! :) (I've overlooked the li position)
Tomalak