Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Shadows all four sides of div

I want to achieve this in CSS - not CSS3 as I want it to be supported by all browsers bg with shadows on all sides

ie a div containing content, with the shadows on every side. The top area will be used for navigation. I have searched for tutorials but so far to no avail. Help!

like image 286
Sean McRaghty Avatar asked Aug 12 '10 12:08

Sean McRaghty


People also ask

How do you make a 4 sided shadow in CSS?

box-shadow: h-shadow v-shadow blur spread color inset; In your example you're offsetting shadow by 10px vertically and horizontally. Like in other comments set first two values to 0px in order to have even shadow on all sides.

How do you get a box shadow all around?

The CSS code would be: box-shadow: 0 0 10px 5px white; That will shadow the entire DIV no matter its shape!


7 Answers

Box Shadow works in all mordern [IE>8] browsers, This code uses no images and works in all browsers in IE versions below 9.

 box-shadow:2px 2px 10px 10px #C9C9C9;
 -webkit-box-shadow:2px 2px 10px 10px #C9C9C9;
 -moz-box-shadow:2px 2px 10px 10px #C9C9C9;

  /* For IE<9 */  
  filter:
  progid:DXImageTransform.Microsoft.Shadow(color=#C9C9C9,direction=0,strength=5),
  progid:DXImageTransform.Microsoft.Shadow(color=#C9C9C9,direction=45,strength=2),
  progid:DXImageTransform.Microsoft.Shadow(color=#C9C9C9,direction=90,strength=5),
  progid:DXImageTransform.Microsoft.Shadow(color=#C9C9C9,direction=135,strength=5),
  progid:DXImageTransform.Microsoft.Shadow(color=#C9C9C9,direction=180,strength=10),
  progid:DXImageTransform.Microsoft.Shadow(color=#C9C9C9,direction=225,strength=5),
  progid:DXImageTransform.Microsoft.Shadow(color=#C9C9C9,direction=270,strength=5),
  progid:DXImageTransform.Microsoft.Shadow(color=#C9C9C9,direction=315,strength=2);

Box shadow supported from IE 9 onwards.

like image 57
vkGunasekaran Avatar answered Oct 05 '22 21:10

vkGunasekaran


CSS3pie is a tool that lets you use some css3 properties in IE.

What you're trying to do is fairly widespread css3 in newer browsers, and emulated really well (and easily) in IE with the .htc file you can download from there.

As for the markup, I see just 2 elements, with the top one floated right, for example. You'd have to play with z-index to hide excess shadows. In that site there's also a very similar effect, you should be able to adapt it for your needs.

like image 21
Razor Avatar answered Oct 05 '22 22:10

Razor


This should work in all browsers:


    .allSidesShadow {
        box-shadow: 2px 2px 19px #aaa;
        -o-box-shadow: 2px 2px 19px #aaa;
        -webkit-box-shadow: 2px 2px 19px #aaa;
        -moz-box-shadow: 2px 2px 19px #aaa;

        /* For IE 5.5 - 7 */
        /* for IE4 - IE7 */
        filter:
            progid:DXImageTransform.Microsoft.Shadow(Strength=9, Direction=1, Color=#C4C4C4),
            progid:DXImageTransform.Microsoft.Shadow(Strength=9, Direction=90, Color=#C4C4C4),
            progid:DXImageTransform.Microsoft.Shadow(Strength=9, Direction=180, Color=#C4C4C4),
            progid:DXImageTransform.Microsoft.Shadow(Strength=9, Direction=270, Color=#C4C4C4);
        -ms-filter: "
            progid:DXImageTransform.Microsoft.Shadow(Strength=9, Direction=1, Color=#C4C4C4),
            progid:DXImageTransform.Microsoft.Shadow(Strength=9, Direction=90, Color=#C4C4C4),
            progid:DXImageTransform.Microsoft.Shadow(Strength=9, Direction=180, Color=#C4C4C4),
            progid:DXImageTransform.Microsoft.Shadow(Strength=9, Direction=270, Color=#C4C4C4)
        ";
    }

like image 36
Ivelin Avatar answered Oct 05 '22 23:10

Ivelin


As Ventus said is not possible to use css shadows with ie (only ie9). But you can use shadowOn. It's a great jquery plugin and very easy in use. With it you will have cross browser compatibility.

like image 25
Sotiris Avatar answered Oct 05 '22 23:10

Sotiris


The answer posted by Sekar, needs a little editing,

box-shadow:2px 2px 10px 10px #C9C9C9;
-webkit-box-shadow:2px 2px 10px 10x #C9C9C9;
-moz-box-shadow:2px 2px 10px 10px #C9C9C9;

this doesnot work on IE(I checked on IE8).

like image 22
Prabhat Ranjan Avatar answered Oct 05 '22 22:10

Prabhat Ranjan


box-shadow: inset 0 0 3px 0 #000;

Means 0 pixel left, 0 pixel right, 3px blur, 0 pixel diffuse, use a color slightly darker than the BGs.

like image 23
yPhil Avatar answered Oct 05 '22 23:10

yPhil


I cant see your picture now, but for all side shadows I use the below code:

box-shadow: 0 0 5px 0 #000;

Instead of the 5px use your size.

like image 20
ravish.hacker Avatar answered Oct 05 '22 21:10

ravish.hacker