【发布时间】:2014-05-18 18:39:49
【问题描述】:
回答了我自己的问题。答案如下:
table, th, td { border:1px solid black; padding-left:4px; padding-right:4px; }
input[type="text"], button, select
{ width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box; }
在我的网页(下面的源代码)中,有几个元素没有填满表格单元格的宽度:输入文本字段、成绩选择和插入按钮。我想要的结果是 我希望每个都填充其表格单元格的宽度,但在它周围有一点填充,就像删除按钮在它周围一样。
我尝试了各种 CSS 样式组合,包括“width:100%”、“padding:2px”等。但是,我一直无法获得组合以产生所需的结果。有谁知道我怎样才能达到我想要的结果?
我使用的是 Chrome 版本 33.0.1750.154 m,我的 HTML 源代码是:
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Presidential Grade</title>
<style>
table, th, td { border:1px solid black; }
fieldset { border-style:solid; border-color:red; display:inline-block; }
legend { font-style:italic; text-align:center; font-weight:bold; }
select { font-family:"Lucida Console", Monaco, monospace; }
</style>
</head>
<body>
<form>
<div>
<fieldset>
<legend> Presidential Grade </legend>
<table>
<tr>
<th>Action</th>
<th>
Last Name<span style='color:green;'> ▴ </span>
</th>
<th> First Name </th>
<th>
Grade<span style='color:green;'> ▴ </span> </th>
</tr>
<tr>
<td><button>Delete</button></td>
<td>
<input type='text' maxlength='20' size='7' value='Adams'>
</td>
<td>
<input type='text' maxlength='20' size='7' value='John'>
</td>
<td>
<select>
<option value='A'>A</option>
<option value='B'>B</option>
<option value='C'>C</option>
<option value='D'>D</option>
</select>
</td>
</tr>
<tr style='background-color:#D0FFD0;'>
<td><button>Insert</button></td>
<td style='display:none;'></td>
<td>
<input type='text' style='color:DarkBlue;' maxlength='20' size='7'>
</td>
<td>
<input type='text' style='color:DarkBlue;' maxlength='20' size='7'>
</td>
<td>
<select>
<option value='A'>A</option>
<option value='B'>B</option>
<option value='C'>C</option>
<option value='D'>D</option>
</select>
</td>
</tr>
</table>
</fieldset>
</div>
</form>
</body>
</html>
【问题讨论】:
标签: html css width margin padding