1 回答

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊
我添加了一些演示 CSS 來展示如何解決這個(gè)引用問題。單擊“運(yùn)行”按鈕查看其運(yùn)行情況。
盡管您可以將類添加到每個(gè)標(biāo)記上,但指定所需<td>的子標(biāo)記會(huì)更容易。tr為此,您可以使用偽類first-child、nth-child和last-child。我在您的示例中添加了一些隨機(jī)格式 - 我將把具體的格式定義留給您。
您當(dāng)然可以用于nth-child所有這些。通常,編程中的枚舉從零開始(“零索引”),但此類是一索引的。因此,first-child我可以用fornth-child(1)來代替。以類似的方式,last-child可以在這里寫為nth-child(3),但在某些情況下可能不太容易維護(hù),因?yàn)槿绻阆氩迦胍涣校阋脖仨氄{(diào)整最右邊一列的 CSS。
<!DOCTYPE html>
<html>
<head>
<style>
table {
? border-collapse: collapse;
? width: 100%;
}
th, td {
? padding: 8px;
? text-align: left;
? border-bottom: 1px solid #ddd;
}
table tr td:first-child {
? ? font-weight: bold;
? ? color: red;
}
table tr td:nth-child(2) {
? ? font-size: 0.8em;
? ? color: purple;
}
table tr td:last-child {
? ? font-style: italic;
? ? color: green;
}
</style>
</head>
<body>
<h2>Bordered Table Dividers</h2>
<p>Add the border-bottom property to th and td for horizontal dividers:</p>
<table>
? <tr>
? ? <th>Firstname</th>
? ? <th>Lastname</th>
? <th>Savings</th>
? </tr>
? <tr>
? ? <td>Peter</td>
? ? <td>Griffin</td>
? ? <td>$100</td>
? </tr>
? <tr>
? ? <td>Lois</td>
? ? <td>Griffin</td>
? ? <td>$150</td>
? </tr>
? <tr>
? ? <td>Joe</td>
? ? <td>Swanson</td>
? ? <td>$300</td>
? </tr>
? <tr>
? ? <td>Cleveland</td>
? ? <td>Brown</td>
? ? <td>$250</td>
? </tr>
</table>
</body>
</html>
- 1 回答
- 0 關(guān)注
- 171 瀏覽
添加回答
舉報(bào)