views:

65

answers:

3

I have a simple drop down list and like to add shadow, it seem hard to find a working code, what do you suggest?

<select>
<option>apple</option>
</select>
+1  A: 
jAndy
Please try it before you answer.
fabrik
Yeah, it not worked, I did try this solution long ago.
JohnMax
I'm guessing that he wants the shadow to be on the drop-down itself, not the select element.
Douglas
@Douglas: should not be that kind of a problem. It would require a little more effort and `mouseup / down` event handlers to add on each `select`. Modifying the underlying div height.
jAndy
works fine in FF, not in ie7 alas
jim
@jim: obviously, IE7 does not support css3 box-shadow
jAndy
andy, no worries. wasn't aware of that - am now :).
jim
A: 

take a look ath this: http://www.cssplay.co.uk/menus/pro_drop9.html

ITroubs
+1  A: 

Well, here's something I threw together rather quickly. It relies on Modernizr for feature detection, and wraps each select with a div that has a box-shadow set to it.

if (Modernizr.boxshadow) {
    $('select').wrap('<div class="shadow" />').parent().width(function() {
        return $(this).outerWidth() - 2
    }).height(function() {
        return $(this).outerHeight() - 2
    });
}

This code attempts to shrink the outer div by 2px to compensate for browser padding. And the CSS:

.shadow {
    -moz-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);
    -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);

    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;

    display: inline-block;
}

Not particularly effective, but still better than nothing. The main problem here would be that different Operating System's default form styles could be different. I've set a rather large border-radius for this, but I believe OSX's selects are rounder than that, though I don't have anything on hand to test it out.

See: http://jsfiddle.net/ykZCz/5/ for the live version.

Yi Jiang
The problem is OSX's width and height is smaller 2-2 pixels. Rounded corners are fine.
fabrik
@fabrik Sigh... this probably won't work unless we manually set the `border-radius` on the `select` element itself.
Yi Jiang