【发布时间】:2014-06-04 14:49:44
【问题描述】:
我正在尝试设置这样的表单:
- 所有输入都将水平对齐,即使它们没有标签。
- 当标签换行时,输入将在其行内垂直对齐。
- 输入将拉伸以填充剩余空间(或压扁)
- 提交按钮将填满一整行。
我已经达到了第一个和第四个要求,但我无法让输入填满行并垂直对齐。
这是我到目前为止的进展: http://jsbin.com/kozozabo/3/edit?html,css,output
少:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
#narrow-form {
width: 300px;
overflow: hidden;
padding-right: 0.5em;
}
#wide-form {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin-left: 300px;
}
.row {
@label-width: 100px;
width: 100%;
overflow: hidden;
label {
width: @label-width;
float: left;
display: inline-block;
}
.no-label {
margin-left: @label-width;
}
input, select {
/* Trying to make these aligned to the right of
* their respective labels filling any remaining
* width.
*/
display: inline-block;
}
button {
width: 100%;
}
}
我尝试使用与标签相同宽度的左边距为输入提供绝对定位,但这不起作用。
【问题讨论】:
-
你可以在它们周围制作一个容器并让输入 100%?
-
你可以用一张桌子。
-
我希望不必更改 DOM,因为此表单是由 javascript 构建的。我已经设法使用
display和table*属性获得了一个版本,但是在对齐无标签输入时没有遇到问题。 jsbin.com/kozozabo/5/edit