我正在尝试在 html 表格中的列之间设置间距,
实际上,我只是想在每列的右侧留出间距。
到目前为止,我只设法使用 border-spacing 属性来增加每列之间的间距。当我使用这个属性时,我意识到每列的左侧和右侧都有间距。是否可以使用 css 规则只在右侧应用间距?
下面是我当前方法的代码片段:
.table{
border-spacing: 10px 0;
}
<!DOCTYPE html>
<html>
<head>
<title>html table</title>
</head>
<body>
<!-- Start your code here -->
<table class="table" >
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td><input type="text" value="some text"/></td>
<td><input type="text" value="another text"/></td>
<td><input type="text" value="looks like you giving"/></td>
</tr>
</table>
<!-- End your code here -->
</body>
</html>
感谢您的帮助。
最佳答案
您不能在表格的特定部分应用间距,也不能在 td
上放置边距也不td
,对此的某种解决方案是在 <td>
上使用填充.
table {
border-spacing: 0;
}
td {
padding-right: 10px
}
<!--border for refrence -->
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
</tr>
</table>
或使用 >*
直接子级的边距
table {
border-spacing: 0;
}
td>* {
margin-right: 10px
}
<!--border for refrence -->
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
</tr>
</table>
关于HTML 表格边框间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50821653/