我想用两列分割每一行,第一个div宽度取决于文本宽度,剩余的全宽度将分配给第二个div。我附上了样本表格设计。
答案 0 :(得分:1)
使用flex-box
,你可以这样做:
Working Fiddle 经过测试: Chrome,IE10,FF(CSS看起来很混乱)
<强> HTML:强>
<div class="Row">
<div class="label"><label>short</label></div>
<div class="input"><input type="text" value="text goes here" /></div>
</div>
<div class="Row">
<div class="label"><label>this is a long label</label></div>
<div class="input"><input type="text" value="text goes here" /></div>
</div>
<强> CSS:强>
*
{
padding: 0;
margin: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.Row
{
border: 1px solid black;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-direction: normal;
-moz-box-direction: normal;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-box-pack: start;
-moz-box-pack: start;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-align-content: stretch;
-ms-flex-line-pack: stretch;
align-content: stretch;
-webkit-box-align: start;
-moz-box-align: start;
-webkit-align-items: flex-start;
-ms-flex-align: start;
align-items: flex-start;
}
.Row > div
{
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
}
.label
{
-webkit-box-flex: 0;
-moz-box-flex: 0;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
/*apply padding if you want*/
}
.input
{
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1 0 auto;
-ms-flex: 1 0 auto;
flex: 1 0 auto;
/*apply padding if you want*/
}
.input input
{
width: 100%;
}
答案 1 :(得分:0)
li .div1 {float:left;} li .div2 {* zoom:1; overflow:hidden;}