gpt4 book ai didi

html - 悬停时显示表格行边框

转载 作者:太空宇宙 更新时间:2023-11-04 01:11:09 26 4
gpt4 key购买 nike

我使用一个 div 表,但是当我在行上设置 hover 时,它不起作用,标题/.thead 没问题,但是在 < strong>.tbody 它不起作用,悬停仅显示 left borderright borderbottom border ,我是不是忘了什么?如何解决?这是我的代码:

.divTable {
display: table;
width: 100%;
border-collapse: collapse;
border-spacing: 0 5px;
}

.divTable .tr {
display: table-row;
}

.divTable .thead {
display: table-header-group;
}

.divTable .td,
.th {
display: table-cell;
padding: 3px 10px;
}

.divTable .thead {
display: table-header-group;
font-weight: bold;
}

.divTable .tfoot {
display: table-footer-group;
font-weight: bold;
}

.divTable .tbody {
display: table-row-group;
}

.divTable {
font-size: 12px;
cursor: default;
width: 100%;
}

.divTable .th,
.divTable .td {
padding: 4px 6px;
}

.divTable .tr {
border: 1px solid white;
height: 26px;
}

.divTable .tr:hover {
background-color: rgba(162, 216, 242, 0.14);
border: 1px solid rgba(124, 204, 243, 0.58);
border-top: 1px solid rgba(124, 204, 243, 0.58);
height: 26px;
}
<div class="divTable">
<div class="thead">
<div class="tr">
<div class="th">Filename</div>
<div class="th">Type</div>
<div class="th">Size</div>
</div>
</div>
<div class="tbody">
<div class="tr">
<div class="td">Why Cannot Work.jpg</div>
<div class="td">Image</div>
<div class="td">12.1 KB</div>
</div>
<div class="tr">
<div class="td">Lorem Ipsum.jpg</div>
<div class="td">Image</div>
<div class="td">12.1 KB</div>
</div>
<div class="tr">
<div class="td">Dolor Sir Amet.jpg</div>
<div class="td">Image</div>
<div class="td">12.1 KB</div>
</div>
</div>
</div>

最佳答案

我相信就是这样border-collapse之所以有效,是因为上部单元格的底部边框折叠到底部单元格的顶部边框中。

解决此问题的方法之一是在 .td 上指定边框元素。所以你会给所有的顶部和底部边框 .td单元格和左右边框分别为 :first-child:last-child分别。这将有效地实现您想要的。

.divTable .tr:hover .td {
border-top: 1px solid rgba(124, 204, 243, 0.58);
border-bottom: 1px solid rgba(124, 204, 243, 0.58);
}

.divTable .tr:hover .td:first-child {
border-left: 1px solid rgba(124, 204, 243, 0.58);
}

.divTable .tr:hover .td:last-child {
border-right: 1px solid rgba(124, 204, 243, 0.58);
}

这是一个片段,展示了它的外观:

.divTable {
display: table;
width: 100%;
border-collapse: collapse;
border-spacing: 0 5px;
}

.divTable .tr {
display: table-row;
}

.divTable .thead {
display: table-header-group;
}

.divTable .td,
.th {
display: table-cell;
padding: 3px 10px;
}

.divTable .thead {
display: table-header-group;
font-weight: bold;
}

.divTable .tfoot {
display: table-footer-group;
font-weight: bold;
}

.divTable .tbody {
display: table-row-group;
}

.divTable {
font-size: 12px;
cursor: default;
width: 100%;
}

.divTable .th,
.divTable .td {
padding: 4px 6px;
}

.divTable .tr {
border: 1px solid white;
height: 26px;
}

.divTable .tr:hover {
background-color: rgba(162, 216, 242, 0.14);
border: 1px solid rgba(124, 204, 243, 0.58);
height: 26px;
}

.divTable .tr:hover .td {
border-top: 1px solid rgba(124, 204, 243, 0.58);
border-bottom: 1px solid rgba(124, 204, 243, 0.58);
}

.divTable .tr:hover .td:first-child {
border-left: 1px solid rgba(124, 204, 243, 0.58);
}
.divTable .tr:hover .td:last-child {
border-right: 1px solid rgba(124, 204, 243, 0.58);
}
<div class="divTable">
<div class="thead">
<div class="tr">
<div class="th">Filename</div>
<div class="th">Type</div>
<div class="th">Size</div>
</div>
</div>
<div class="tbody">
<div class="tr">
<div class="td">Why Cannot Work.jpg</div>
<div class="td">Image</div>
<div class="td">12.1 KB</div>
</div>
<div class="tr">
<div class="td">Lorem Ipsum.jpg</div>
<div class="td">Image</div>
<div class="td">12.1 KB</div>
</div>
<div class="tr">
<div class="td">Dolor Sir Amet.jpg</div>
<div class="td">Image</div>
<div class="td">12.1 KB</div>
</div>
</div>
</div>

关于html - 悬停时显示表格行边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51183613/

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