Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an inset dark drop shadow effect with CSS

I'm trying to get an effect like an inset drop shadow effect in CSS that looks like the following image:

image of sunken button
(source: gyazo.com)

Does any body know how I can get that effect with CSS?

like image 434
endy Avatar asked Jun 14 '11 12:06

endy


3 Answers

The key here is multiple box shadows, a larger darker one inset from the top left and a very subtle shadow below thats slightly brighter than the background.

Notice the form of box-shadow is "x-offset, y-offset, blur, color"

Learn to use the blur amounts and multiple shadows and you can make some really nice effects.

Example style (for display on a background of #222):

.button {
    display:inline-block;
    padding: 10px 15px;
    color: white;
    border-radius: 20px;
    box-shadow: inset 2px 3px 5px #000000, 0px 1px 1px #333;
}
like image 190
theozero Avatar answered Oct 28 '22 21:10

theozero


The answer has already been given to you (box-shadow: inset ..), so here's a quick demonstration of how it could work:

http://jsfiddle.net/L6nJj/

The important part is box-shadow: inset 2px 2px 3px 0 red.

For an explanation of the available options: https://developer.mozilla.org/en/css/box-shadow#Values

Be sure to take into account the browser support for box-shadow, which is that it doesn't work in older versions of IE, but works "everywhere" else: http://caniuse.com/css-boxshadow

like image 33
thirtydot Avatar answered Oct 28 '22 23:10

thirtydot


Have a look at the CSS3 box-shadow property, in particular, inset box shadows. Example L in this article should provide the effect you're looking for.

like image 24
James Allardice Avatar answered Oct 28 '22 23:10

James Allardice