使用bootstrap创建的表单,元素均设置了"width:100%",但在td中插入了一个span后,select输入框的宽度未能像input那样撑满单元格,如下测试代码:
<html>
<head>
<style type="text/css">
td {width: 200px; display: table;}
input, select {width: 100%; display: table-cell;}
span.unit {display: table-cell; background-color: lightgreen;}
</style>
</head>
<body>
<table>
<tr><td><input type="text"></input><span class="unit">元</span></td></tr>
<tr><td><select></select><span class="unit">元</span></td></tr>
</table>
</body>
</html>
显示结果为:
如何调整css才能使select和input的宽度保持一致?
因为display:table-cell是自适应宽度的。如果你将input,select跟后面的span分开就可以了。