gpt4 book ai didi

html - 仅在 tbody 上具有透明边框的表格

转载 作者:行者123 更新时间:2023-11-28 03:01:25 25 4
gpt4 key购买 nike

table
{
background-color: lime;
border-collapse: collapse;
}

tr
{
border-width: 0 0 1px 0;
border-style: solid;
}
tr:last-child
{
border: none; // so the last child from thead and tbody dont have border
}
<table>
<thead>
<th>Rank</th>
<th>Player</th>
<th>Pts</th>
</thead>
<tbody>
<tr>
<td>1</td>
<td>player1</td>
<td>50</td>
</tr>
<tr>
<td>2</td>
<td>player2</td>
<td>40</td>
</tr>
<tr>
<td>3</td>
<td>player3</td>
<td>30</td>
</tr>
<tr>
<td>4</td>
<td>player4</td>
<td>40</td>
</tr>
</tbody>
</table>

现在,我想要行之间的透明边框,但只有 tbody 内的行,而不是 thead 和 tbody 之间的行。首先,我尝试了

table {
border-collapse: collapse;

tr {
border-width: 0 0 1px 0;
border-style: solid;
}
tr:last-child {
border: none; // so the last child from thead and tbody dont have border
}
}

在这种情况下,我得到了我想要的元素的边框,但它是黑色的并且不透明。然后我尝试使用边框间距:

table {
border-spacing: 0 1px;
tr:last-child {
border: none;
border-spacing: none; //those two don't seem to work
}
}

现在我有了透明边框,但是 thead 前后也有边框,我无法消除。所以,我现在要么: 1. 边框只在 tbody 而不是在 thead 和第一个数据行之间(好),但边框不透明(坏)或者 2. 透明边框(好),但广告和第一个数据行之间不需要的边框(坏)。

有没有一种方法可以将其结合起来,使我有透明的边框,但不是在 thead 和第一个数据行之间?

enter image description here

编辑:我希望边框完全透明,但是只要我用 rgba(0,0,0,0) 设置边框颜色,边框就会“消失”。好的,它并没有真正消失,但是从 td 中获取背景颜色(浅灰色,这也是一个 rgba 值),我不知道为什么。

最佳答案

使用 border-color: rgba(0,0,0,.5);

<!DOCTYPE html>
<html>
<head>
<style>
table
{
background:yellow;
border-spacing: 0;
}

tbody tr:not(:last-of-type) td
{
border-width: 0 0 5px 0;
border-style: solid;
border-color:black;
border-color: rgba(0,0,0,.5);

}
</style>
</head>
<body>

<table>
<thead>
<th>Rank</th>
<th>Player</th>
<th>Pts</th>
</thead>
<tbody>
<tr>
<td>1</td>
<td>player1</td>
<td>50</td>
</tr>
<tr>
<td>2</td>
<td>player2</td>
<td>40</td>
</tr>
<tr>
<td>3</td>
<td>player3</td>
<td>30</td>
</tr>
<tr>
<td>4</td>
<td>player4</td>
<td>40</td>
</tr>


</body>
</html>

关于html - 仅在 tbody 上具有透明边框的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46175321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com