------------- --------------------------------------------------
| some text | | some more text, sometimes more, sometimes less |
------------- --------------------------------------------------
|<------------------------- 100% width ----------------------->|
我有上面的布局。左边的框应该尽可能小,而右边的框应该占据剩余的空间。通常使用 float: left
就可以实现。
问题是右边的框可能会增长很多,而左边的框基本上保持很小(但大小会变化,因此需要灵活处理)。如果右框增长,我需要它表现出以下行为:
------------- --------------------------------------------------
| some text | | quite a lot of text, actually, really quite a |
------------- | bunch of it, you could say this is really |
| quite a heck of a lot of text |
--------------------------------------------------
如果我使用 float:left
,右侧的盒子会在包含大量文本时换行到左侧盒子下方:-------------
| some text | (not good)
-------------
----------------------------------------------------------------
| quite a lot of text, actually, really quite a bunch of it, |
| you could say this is really quite a heck of a lot of text |
----------------------------------------------------------------
如果我为这两个元素都使用表格,当两个元素都只包含很少的文本时,左边的框可能会不必要地变得很宽:
(not good)
-------------------------------- -------------------------------
| some text | | not that much text |
-------------------------------- -------------------------------
此外,左侧的框不应该换行。但由于它包含一些HTML元素而不仅仅是纯文本,所以在所有浏览器中都似乎不能使用no-wrap
。
有什么好的解决方案吗?
编辑
实际上,右侧的框占据剩余宽度并不是非常重要,只要它始终附着在左侧框的右侧即可。