【发布时间】:2012-01-21 17:25:50
【问题描述】:
我有一个非常简单的数据输入表格。只是带有输入的标签。但是我的标签是本地化的,所以我不知道不同语言的文本会有多长。这个问题很容易通过表格布局解决:
<table>
<tr>
<td>
<label for="Text1">Short</label>
</td>
<td>
<input id="Text1" type="text" />
</td>
</tr>
<tr>
<td>
<label for="Text1">Looooooooong</label>
</td>
<td>
<input id="Text2" type="text" />
</td>
</tr>
</table>
无论标签有多长,我的布局都会很好。但是我们很多人说使用带有非表格数据的表格标签并不好。我现在不知道如何用 div 解决这个问题。
<div>
<div style="float:left; width:50px;"><label for="Text3">Short</label></div>
<div style="float:left;"><input id="Text3" type="text" /></div>
<br style="clear:left;" />
</div>
<div>
<div style="float:left; width:50px;"><label for="Text4">Looooooooong</label></div>
<div style="float:left;"><input id="Text4" type="text" /></div>
<br style="clear:left;" />
</div>
有了这个解决方案,我需要使用固定大小的 div。当然,我可以为标签 div 的宽度设置一些较大的值,但我希望我的 UI 占用尽可能多的空间。 有什么想法吗?
【问题讨论】:
-
你有设置宽度的容器吗?还是您的表单占用了页面上的所有空间?
标签: html css html-table