CSS box-shadow on table rows - tr
- doesn\'t seem to be working consistently across browsers. On some browsers the shadow is displayed; on others, there is no s
Use transform scale(1,1) property with box-shadow it will solve the problem.
tr:hover {
transform: scale(1);
-webkit-transform: scale(1);
-moz-transform: scale(1);
box-shadow: 0px 0px 5px rgba(0,0,0,0.3);
-webkit-box-shadow: 0px 0px 5px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 5px rgba(0,0,0,0.3);
}
Fiddle: https://jsfiddle.net/ampicx/5p91xr48/
Thanks!!
I had the same issue. I was trying to highlight an entire row when the mouse was over it. Below is the css code for it:
tr:hover {
outline: none;
-webkit-box-shadow: inset 0 0 10px #337AB7;
box-shadow: inset 0 0 10px #337AB7;
}
It works fine on Mozilla Firefox (38.0.1) and Internet Explorer (11.0.9600.17801), both on Windows 7. However, did not work on Chrome (43.0.2357.81).
Therefore, I had to workaround and I did a mix of the answers of Sviatoslav Zalishchuk and David Winiecki. As an result I got:
@media screen and (-webkit-min-device-pixel-ratio:0) {
tr:hover td:first-child {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7,
inset 11px 0px 8px -10px #337AB7;
}
tr:hover td {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7;
}
tr:hover td:last-child {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7,
inset -11px 0px 8px -10px #337AB7;
}
}
tbody > tr:hover {
outline: none;
-webkit-box-shadow: inset 0 0 10px #337AB7;
box-shadow: inset 0 0 10px #337AB7;
}
That works fine and it does not break the column width of the table and still working on Mozilla and Explorer.
Below there is a full example:
table {
box-sizing: border-box;
border-collapse: collapse;
}
td,
th {
padding-left: 10px;
padding-right: 10px;
border: 1px solid #ffffdffffd;
font: 14px;
text-align: left;
}
/*To work only on Chrome and Safari*/
@media screen and (-webkit-min-device-pixel-ratio:0) {
tr:hover td:first-child {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7,
inset 11px 0px 8px -10px #337AB7;
}
tr:hover td {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7;
}
tr:hover td:last-child {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7,
inset -11px 0px 8px -10px #337AB7;
}
}
/*To work on the others browsers*/
tbody > tr:hover {
outline: none;
-webkit-box-shadow: inset 0 0 10px #337AB7;
box-shadow: inset 0 0 10px #337AB7;
}
<table>
<thead>
<tr>
<th>Name</th>
<th>Born</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>David Gilmour</td>
<td>6 March 1946</td>
<td>Cambridge, England</td>
</tr>
<tr>
<td>Roger Waters</td>
<td>6 September 1943</td>
<td>Surrey, England</td>
</tr>
<tr>
<td>Nick Mason</td>
<td>27 January 1944</td>
<td>Birmingham, England</td>
</tr>
<tr>
<td>Richard Wright</td>
<td>28 July 1943</td>
<td>London, England</td>
</tr>
</tbody>
</table>
I wanted a box-shadow on the left side of the row when hovered:
I fixed it simply by setting the box-shadow on the first cell in the row. Like this:
tr:hover { background: #EEF0F3; cursor: pointer; }
tr:hover td:first-child { box-shadow: inset 2px 0 0 0 #323335; }
I've tried it in Firefox, Chrome, and IE9. Seems to work fine.
If you want a 1px wide border around the whole row you could do something like:
tr:hover td { box-shadow: 0 1px 0 0 black, 0 -1px 0 0 black; }
tr:hover td:first-child { box-shadow: 0 -1px 0 0 black, -1px 0 0 0 black, 0 1px 0 0 black; }
tr:hover td:last-child { box-shadow: 0 -1px 0 0 black, 1px 0 0 0 black, 0 1px 0 0 black; }