twitter-bootstrap - 带透明边框的 Bootstrap 4 表
问题描述
我试图使行之间的边界透明,以便页面背景的颜色显示出来。
边框来自 td,背景颜色来自 tr,所以如果我让 td 边框透明,则 tr 的背景会透出来。我已经尝试删除 th td 边框并仅使用 tr 边框,但我似乎无法让边框出现。
考虑下表,使用标准的 bootstrap 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>
解决方案
表格边框可能很棘手。相反,只需将单元格隔开。
body {
background-color: lightgreen;
}
.table {
width: 100%;
border-collapse: separate; /* boom */
border-spacing: 0 5px; /* bam */
}
.table td {
background-color: pink;
border: 5px solid transparent;
}
.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
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />
<div>
<table class="table">
<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>
推荐阅读
- ns-3 - 如何在 NS-3 中使用 TCP 获取丢失数据包的数量?(80211n + MIMO 示例)
- javascript - FullCalendar-v4 allDay 事件未呈现
- python - Django ModelFormSet 单击“提交”保存表单但不更新到数据库
- amazon-web-services - 如何 Terraform 规划多个 AWS 账户,然后审核,然后应用到多个账户
- swift - 在服务器上存储密码
- javascript - 应用程序已加载时 PWA 更新服务工作者
- maven - 如何强制 Maven 使用特定的存储库(仅此而已)?
- javascript - 有没有办法让屏幕 100% 的高度和宽度,但是当按比例缩小时总是足够大以包含子元素
- flask - 如何在 python 包的烧瓶静态文件夹中动态保存?
- json - 如何将flutter中的日期解析为与Java ZonedDateTime兼容的json字符串