这可能没有JavaScript,请参阅:
http://jsfiddle.net/Khmhk/
这在IE7和所有现代浏览器。
HTML:
Label
CSS:
label {
float: left
}
span {
display: block;
overflow: hidden;
padding: 0 4px 0 6px
}
input {
width: 100%
}
之所以溢出:隐藏是如此神奇地有用在这个例子是explained here。
display:table-cell是另一个选项,参见:http://jsfiddle.net/Khmhk/1/
HTML:
Label
CSS:
.container {
display: table;
width: 100%
}
label {
display: table-cell;
width: 1px;
white-space: nowrap
}
span {
display: table-cell;
padding: 0 0 0 5px
}
input {
width: 100%
}