代码之家  ›  专栏  ›  技术社区  ›  Tomalak

浮动框的HTML布局帮助

css
  •  1
  • Tomalak  · 技术社区  · 15 年前

    创建这种HTML布局需要什么CSS:

    +--[li]---------------------------------------------+
    |+--[div]-------------------------------------++---+|
    || A label with some text, truncate if necess…||BOX||
    |+--------------------------------------------++---+|
    |+--[div]------------------------------------------+|
    || Another label, truncate if necessary            ||
    |+-------------------------------------------------+|
    +---------------------------------------------------+
    
    • 外部 <li> 是固定宽度,与列表中的其他列表项一起向左浮动
    • 盒子应该向右浮动,在上面 <div> ,只有两个字母
    • 中没有任何文本 <DIV & GT; s应该换行,溢出应该隐藏
    • 最好是在IE7怪癖模式下工作。

    目前我有:

    <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>
    

    但我不能让盒子停留在第一个标签上。

    3 回复  |  直到 15 年前
        1
  •  1
  •   Zenya    15 年前

    这是因为右浮动的DIV不能围绕不可压缩的文本浮动。

    试试这个

    <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>
    

    如果这是你想要的。

        2
  •  1
  •   Daniel Vassallo    15 年前

    这是预期结果吗?

    alt text http://img51.imageshack.us/img51/6603/boxf.jpg

    <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>
    

    省略 position: relative 你会得到:

    alt text http://img360.imageshack.us/img360/7205/box2.jpg

        3
  •  0
  •   Roberto Aloi    15 年前

    你试过了吗? float: left 第一个标签?

    顺便说一句,Firebug在调试方面会帮你很多…