Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox and Chrome seem to render box-shadow quite differently

I was testing a box-shadow effect in both Chrome and Firefox and I was surprised to see a drastic difference in rendering between the two browsers. Notably, Firefox's rendering was much darker. Here are two reference images:

ChromeFirefox

The first image is rendered in Chrome 22, and the latter in Firefox 16, both running under Mac OS 10.8.2. I have no idea why the two images are rendering so differently. Here's the box shadow itself, same for both browsers:

box-shadow: 0px 1px 3px rgba(0,0,0,0.3), inset 0px 4px 2px -2px rgba(255,255,255,0.7), inset 0px -3px 1px -2px rgba(0,0,0,0.3), inset 0px -20px 200px -100px rgba(0,0,0,0.5);

For a live demo, you can see here. Mouse over the box to get the effect.

Is there any way I can fix this drastic difference in rendering?

like image 812
Alexis King Avatar asked Oct 21 '12 17:10

Alexis King


People also ask

Does Box Shadow work on all browsers?

The box-shadow property of CSS 3 is supported by recent versions of all browsers.

What is box shadow in HTML?

The box-shadow CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.


1 Answers

You can create a media selector for Firefox which will be using a different style. You will have to play around with it. For example, I reduced the blur, the spread and turned up the opacity of the last inset box-shadow. So the CSS for the .box:hover should probably look something like this:

.box:hover {
  box-shadow(0px 1px 3px rgba(0,0,0,0.3), inset 0px 4px 2px -2px rgba(255,255,255,0.7), inset 0px -3px 1px -2px rgba(0,0,0,0.3), inset 0px -20px 200px -100px rgba(0,0,0,0.5));
}

@-moz-document url-prefix() {
.box:hover {
  box-shadow(0px 1px 3px rgba(0,0,0,0.3), inset 0px 4px 2px -2px rgba(255,255,255,0.7), inset 0px -3px 1px -2px rgba(0,0,0,0.3), inset 0px -20px 130px -120px rgba(0,0,0,0.9));
}
}

For more media selectors and other browser hacks you can visit BrowserHacks.com

like image 157
thexpand Avatar answered Oct 29 '22 16:10

thexpand