html - 1px 边框问题不显示
问题描述
我试图在比较表上突出显示特定产品。突出显示颜色是红色,但我在使用 1px 时遇到问题,但是当我使用 2px 时效果很好,但 2px 太大了。
在此代码片段上还注意到它在我添加引导程序后不显示红色边框,因此附上屏幕截图。
我的目标是必须Selected Product
被 RED 1px 边框包围。我也不介意显示这些类型的表格的任何其他提示。
我也试过这个但没有奏效:https ://muffinman.io/fix-for-chrome-not-rendering-borders/
border-collapse: collapse;
如果我删除 BS 并使用相同的问题,看起来这也不是 Bootstrap问题
.table {
margin: 20px;
display: inline-block;
text-align: center;
}
table,
th,
td {
border: 1px solid #ddd;
padding: 10px;
}
th:not(:first-child) {
width: 200px;
}
table,
th {
font-weight: normal;
}
.border-sides {
border-right: 1px solid red !important;
border-left: 1px solid red !important;
}
.border-top {
border-top: 1px solid red !important;
}
.border-bottom {
border-bottom: 1px solid red !important;
}
.bg-selected {
background-color: #b3c2ff;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="table">
<table>
<thead>
<tr>
<th></th>
<th>
<div class="text-left">
<span>Title - Product 1 Test</span>
</div>
</th>
<th class="border border-top">
<div class="text-left">
<span class="font-weight-bold">Selected Product:</span>
<span>Title - Product 2</span>
</div>
</th>
<th>
<div class="text-left">
<span>Title - Product 2</span>
</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>
<button class="btn btn-primary">View</button>
</td>
<td class="border border-sides">
<button class="btn btn-primary">Buy now</button>
</td>
<td>
<button class="btn btn-primary">View</button>
</td>
</tr>
<tr class="text-left">
<td>Description 1</td>
<td>Y</td>
<td class="border bg-selected">N</td>
<td>N</td>
</tr>
<tr class="text-left">
<td class="test">Description 2</td>
<td>N</td>
<td class="border bg-selected">N</td>
<td>N</td>
</tr>
<tr>
<td></td>
<td>
<button class="btn btn-primary">View</button>
</td>
<td class="border border-bottom">
<button class="btn btn-primary">Buy now</button>
</td>
<td>
<button class="btn btn-primary">View</button>
</td>
</tr>
</tbody>
</table>
</div>
解决方案
这是所需的输出吗?
更新
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
<style>
.table {
margin: 20px;
display: inline-block;
text-align: center;
}
table,
.table thead th,
.table td {
border: 1px solid #ddd;
border-collapse: separate;
border-spacing: 0px;
padding: 10px;
}
table {
padding: 0;
border-width: 0 2px 0 0.5px;
}
th:not(:first-child) {
width: 200px;
}
table,
th {
font-weight: normal;
}
.table thead th{
border-top-width: 1px;
}
.table tr:last-child td{
border-bottom-width: 1px;
}
.table thead th, .table td{
border-right: none;
}
.border-sides {
border-right: 1px solid red !important;
border-left: 1px solid red !important;
}
.border-sides + td, .table thead .border-sides + th{
border-left: none;
}
.border-top {
border-top: 1px solid red !important;
}
.border-bottom {
border-bottom: 1px solid red !important;
}
.bg-selected {
background-color: #b3c2ff;
}
</style>
<div class="table">
<table>
<thead>
<tr>
<th></th>
<th>
<div class="text-left">
<span>Title - Product 1 Test</span>
</div>
</th>
<th class="border border-top border-sides">
<div class="text-left">
<span class="font-weight-bold">Selected Product:</span>
<span>Title - Product 2</span>
</div>
</th>
<th>
<div class="text-left">
<span>Title - Product 2</span>
</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>
<button class="btn btn-primary">View</button>
</td>
<td class="border border-sides">
<button class="btn btn-primary">Buy now</button>
</td>
<td>
<button class="btn btn-primary">View</button>
</td>
</tr>
<tr class="text-left">
<td>Description 1</td>
<td>Y</td>
<td class="border bg-selected border-sides">N</td>
<td>N</td>
</tr>
<tr class="text-left">
<td class="test">Description 2</td>
<td>N</td>
<td class="border border-sides bg-selected">N</td>
<td>N</td>
</tr>
<tr>
<td></td>
<td>
<button class="btn btn-primary">View</button>
</td>
<td class="border border-bottom border-sides">
<button class="btn btn-primary">Buy now</button>
</td>
<td>
<button class="btn btn-primary">View</button>
</td>
</tr>
</tbody>
</table>
</div>
推荐阅读
- php - 限制搜索结果的最大数量
- cmake - (Cmake,Trilinos)clang:错误:不支持的选项'-fopenmp'
- java - 迁移到 Spring 5 后出现非法字符错误
- r - 以百分比而不是计数绘制条形图
- ios - 在 MongoDB Realm Sync 中建模子集合
- java - 在 Java 中具有最低延迟的 Rabbit MQ 扇出设置
- python - 使用 Python 创建 Cartisan X、Y、Z 值的热图
- create-react-app - 如何为生产构建设置 Tailwind 响应式变体?
- matlab - 在 Matlab RRT-planner 中创建自定义转向方法
- kendo-ui-angular2 - 如何截断剑道扩展面板组件中的文本