【发布时间】:2019-01-26 05:42:53
【问题描述】:
我正在尝试使行之间的边框透明,以便页面背景的颜色显示出来。
边框来自td,背景色来自tr,所以如果我让td边框透明,tr的背景就会透出来。我尝试删除 th td 边框并仅使用 tr 边框,但我似乎无法让边框出现。
考虑下表,使用标准引导程序 4.2 css:
<div style="background-color:white">
<table class="table table-gap table-striped table-striped-alt">
<tbody>
<tr>
<td>A</td><td>B</td>
</tr>
<tr>
<td>C</td><td>D</td>
</tr>
<tr>
<td>E</td><td>F</td>
</tr>
</tbody>
</table>
</div>
我添加了自己的 CSS。这会为奇数行着色,而标准的 boostrap 表条带颜色为偶数行。它还尝试在 tr 和 th/td 上都显示透明边框,这不起作用:
<style type="text/css">
/*Color the alternating rows that table-striped does not
.table-striped-alt tr:not(:nth-of-type(odd))
{
background-color: #007bff !important;
}
.table-gap tr > *
{
border-top: 3px solid transparent !important;
}
.table-gap tr
{
border-top: 3px solid transparent !important;
}
</style>
所以我尝试将 tr 边框更改为黄色,将 td/th 更改为红色,看看是否有任何影响。 td/th显示了边框,但是tr没有显示边框,td做到了:
<style type="text/css">
.table-striped-alt tr:not(:nth-of-type(odd))
{
background-color: #007bff !important;
}
.table-gap tr > *
{
border-top: 3px solid red !important;
}
.table-gap tr
{
border-top:3px solid yellow !important
}
</style>
所以我玩了border-collapse,并将其设置为'separate',仍然没有在tr上显示边框。它实际上在所有单元格周围都有一个透明的间距。这是不可取的,因为我只想要单元格上方和下方的透明间距。
<style type="text/css">
.table-striped-alt tr:not(:nth-of-type(odd))
{
background-color: #007bff !important;
}
.table-gap tr > *
{
border-top: 3px solid red !important;
}
.table-gap tr
{
border-top:3px solid yellow !important
}
table
{
border-collapse:separate;
}
</style>
【问题讨论】:
标签: twitter-bootstrap bootstrap-4