我已经用纯HTML和CSS完成了棋盘。但由于我不是设计师,我无法弄清楚如何做一件简单的事情。我试图围绕棋盘制作一个框架。我正在使用CSS border属性在table.chessboard
元素中创建一个边距(下面的代码)。但是这个边际在董事会内扩大并减少了边界上的方格。
我该怎么做才能解决这个问题?
码:
table.chessboard {
margin: 80px auto;
background: #999;
border: 25px solid #333;
}
td.chessboard {
width: 70px;
height: 70px;
}
tr.chessboard:nth-child(odd) td.chessboard:nth-child(even),
tr.chessboard:nth-child(even) td.chessboard:nth-child(odd) {
background: white;
}
<table class="chessboard">
<tr class="chessboard">
<td class="chessboard"></td>
<!-- line above 8 times -->
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<!-- line above 8 times -->
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<!-- line above 8 times -->
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<!-- line above 8 times -->
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<!-- line above 8 times -->
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<!-- line above 8 times -->
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<!-- line above 8 times -->
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<!-- line above 8 times -->
</tr>
</table>
我假设你想在所有细胞周围做一个边界。
table.chessboard {
margin: 80px auto;
background: #999;
border: 25px solid #333;
border-collapse: collapse; /* */
}
td.chessboard {
width: 70px; height: 70px;
border: 2px solid #333; /* */
}
tr.chessboard:nth-child(odd) td.chessboard:nth-child(even),
tr.chessboard:nth-child(even) td.chessboard:nth-child(odd) {
background: white;
}
<table class="chessboard">
<tr class="chessboard">
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
</tr>
<tr class="chessboard">
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
<td class="chessboard"></td>
</tr>
</table>
在你的CSS中:
table.chessboard {
border: 2px solid #000;
}
根据需要调整宽度;)