Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table Row Box-Shadow on Hover (Webkit)

Is this possible?

My code works on Firefox. I can also get webkit to change other properties (e.g. background color, etc.) on hover, but the box shadow doesn't take effect:

tr:hover {
    -webkit-box-shadow: 0px 2px 4px #e06547;
    -moz-box-shadow: 0px 2px 4px #e06547;
    box-shadow: 0px 2px 4px #e06547;
    background-color: #d4d5d6;
}
like image 270
Anthony C Avatar asked May 12 '11 01:05

Anthony C


People also ask

How to display table row background color on hover using CSS?

The short answer is: use the CSS :hover selector to apply an effect that displays on hover over the element. It displays table row background color on hover to highlight the row when someone hovers over the row of a table.

How to display a table only on hover?

The color is grey and you can also apply any other background color of your choice to each row of a table to display only on hover. In addition to the above example, you can also highlight table rows with different colors on hover.

Why can't I show a box-shadow in WebKit?

For some reason Webkit needs to explicitly know that the element is a block element to display a box-shadow. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.

How do you put a shadow on a box?

The box-shadow property in CSS is for putting shadows on elements (sometimes referred to as “drop shadows”, ala Photoshop/Figma). The horizontal offset (required) of the shadow, positive means the shadow will be on the right of the box, a negative offset will put the shadow on the left of the box.


2 Answers

As answered here: https://stackoverflow.com/a/11002077/1106393 rather than styling tr you should style the td-element in combination with the pseudo classes :first-child and :last-child. Prepending tr:hover will do the trick for you:

tr:hover td {
    -moz-box-shadow: 0 4px 2px -3px rgba(0, 0, 0, 0.5) inset;
    -webkit-box-shadow: 0 4px 2px -3px rgba(0, 0, 0, 0.5) inset;
    box-shadow: 0 4px 2px -3px rgba(0, 0, 0, 0.5) inset;
}
tr:hover td:first-child {
    -moz-box-shadow: 4px 4px 2px -3px rgba(0, 0, 0, 0.5) inset;
    -webkit-box-shadow: 4px 4px 2px -3px rgba(0, 0, 0, 0.5) inset;
    box-shadow: 4px 4px 2px -3px rgba(0, 0, 0, 0.5) inset;
}
tr:hover td:last-child {
    -moz-box-shadow: 0 4px 2px -3px rgba(0, 0, 0, 0.5) inset;
    -webkit-box-shadow: 0 4px 2px -3px rgba(0, 0, 0, 0.5) inset;
    box-shadow: 0 4px 2px -3px rgba(0, 0, 0, 0.5) inset;
}

Demo 1 with inset: http://jsfiddle.net/Kk6Th/

Update:
Demo 2 without inset (classic drop shadow): http://jsfiddle.net/2nw4t/1/
Demo 3 without inset (glow effect): http://jsfiddle.net/2CSuM/

like image 161
AvL Avatar answered Sep 20 '22 09:09

AvL


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!!

like image 39
Anurag Malhotra Avatar answered Sep 21 '22 09:09

Anurag Malhotra