Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using box shadow on select inputs in Chrome

Tags:

css

I am currently working on a small site, and I have used the box-shadow effect on various elements on the site. It seems to work on all the elements where it has been applied, in both Chrome and Firefox, except for select and input. It will work fine for these input types in Firefox but not in Chrome. Any ideas why?

I have applied this effect using box-shadow, -webkit-box-shadow and -moz-box-shadow for multiple browser support.

like image 467
Hindle Avatar asked Sep 04 '11 16:09

Hindle


People also ask

Does the box shadow support all browsers?

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

Can we apply transform property to box shadow?

Using transforms on the box-shadow (& transform ) property, we can create the illusion of an element moving closer or further away from the user.


2 Answers

Here's a/the solution:

select {-webkit-appearance: none; appearance: none; }

This allows any shadow CSS to apply to SELECT items in Chrome - but removes any other details such as the drop-down arrow. But simply create a small background img (using screen grab) to reinstate this.

You could wrap this CSS in CSS filters to target only Chrome: E.g.

@media screen and (-webkit-min-device-pixel-ratio:0) {/* older safari and older chrome */
  select {-webkit-appearance: none; appearance: none; 
}

If using SELECTS without a given width, add 'padding-right' CSS to account for the new background icon/img. This has worked perfectly for me.

This also works for HTML5 validation icons, etc, when combining an icon with drop-down arrow in one image).

like image 172
Darren Avatar answered Oct 10 '22 20:10

Darren


Here's a workaround:

HTML:

<div><input type="text" /></div>

CSS:

div {
    -webkit-box-shadow: 5px 5px 5px #666;
    -moz-box-shadow: 5px 5px 5px #666;
    box-shadow: 5px 5px 5px #666;
    display:inline-block;
}

Demo: http://jsfiddle.net/AlienWebguy/UD2QP/

like image 20
AlienWebguy Avatar answered Oct 10 '22 21:10

AlienWebguy