Reputation: 411
I work with a div table, but when I set hover on row, it does not work, the header / .thead is all right, but on the .tbody it does not work, the hover only displays left border, right border, and bottom border , did I forget something? How to solve it? This is my code:
.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>
Upvotes: 2
Views: 2881
Reputation: 86
Nisarg's method works, but its much simpler to remove and add just these two lines from your original code. Remove {border: 1px solid white;} from .divTable .tr
and the reason you added this was probably so the cells dont move around when you hover them. Just add {border: 1px solid transparent;} to .divTable
.divTable {
display: table;
width: 100%;
border-collapse: collapse;
border-spacing: 0 5px;
border: 1px solid transparent;
}
.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 {
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>
Upvotes: 1
Reputation: 92
Removing following will solve your problem:
.divTable .tr {
border: 1px solid white;
}
Upvotes: 1
Reputation: 14541
I believe that's how border-collapse
works because the bottom border of upper cell is collapsed into the top border of the bottom cell.
One of the ways of working around this would be to specify borders on the .td
elements. So you would give top and bottom borders to all .td
cells, and left and right borders respectively to the :first-child
and :last-child
respectively. This would effectively achieve what you want.
.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);
}
Here's a snippet showing how that would look:
.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>
Upvotes: 1