2015-09-17 39 views
1

在表格单元格中,我有1个选择元素和1个文本输入元素。 select元素的固定宽度可以设置为100px。CSS使文本输入占用表格单元格宽度的其余部分

如何让文本输入占用单元格宽度的其余部分?

<td> 
    <div> 
     <select> 
     <option>string</option> 
     <option>integer</option> 
     </select> 
     <input type="text"> 
    </div> 
</td> 

table cell with 2 controls

+0

只要表格具有宽度,只需在输入上使用'width:100%'。 – APAD1

+0

您对表格列有定义的宽度吗? –

+0

不,表格根据其容器设置为%宽度。选择的宽度可以设置为70px。文本输入需要占用宽度的其余部分。有没有什么办法可以在CSS中使用javascript来计算剩余宽度? – Believe2014

回答

0

你可以使用浮动属性:

table { 
 
    width:80%;/* for demo */ 
 
} 
 
select { 
 
    width:100px; 
 
    float:left;/* start playing with float */ 
 
} 
 
label {/* or whatever you choose to wrap input */ 
 
    display:block; 
 
    overflow:hidden;/* use a container turned into block to stand aside the float*/ 
 
} 
 
input { 
 
    width:100%;/* spread it all the way in avalaible space */ 
 
}
<table><tr> 
 
<td> 
 
    <div> 
 
     <select> 
 
     <option>string</option> 
 
     <option>integer</option> 
 
     </select> 
 
     <label> 
 
     <input type="text"/> 
 
    </label> 
 
    </div> 
 
</td></tr> 
 
</table>

相关问题