Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Box-Shadow Only on Left and Right

Tags:

css

I am attempting to create an inset box-shadow on an element that only has the shadow on the left and right. I cannot get it to work.

Here is the box-shadow I tried:

 box-shadow: inset 10px 0px 25px 0px rgba(0,0,0,0.45);

I will add another one for the right side. The problem is this setting also shows the shadow slightly on the top and bottom and I cannot get it to not show and still show a shadow on the left side. Is this possible?

jsFiddle

like image 254
L84 Avatar asked Jul 02 '13 03:07

L84


People also ask

How do you box-shadow only left and right?

Probably, the best way is using the CSS box-shadow property with the “inset” value. Also, use the :before and :after pseudo-elements, which are absolutely positioned on the right and left sides of the element.

How do you add a shadow to only one side?

To set a box-shadow on one side of the element, use the box-shadow property. This property has four length parameters and a color. box-shadow: h-offset v-offset blur spread color; h-offset sets the shadow horizontally.

How do you set a box-shadow only on the bottom?

To display the shadow at the bottom of the image, the “box-shadow” property is used. For this purpose, offset-x is set as “0”, offset-y is any positive value, and the color you want to display is also set.

How do you get rid of shadow on one side?

Use a width calc() to position two elements next to each other. Then add the box-shadow to both elements, followed by the clip-path on only one of them. Set the z-index of the clip-path'd element to be higher than the non-clip-path'd element. Here's an example.


1 Answers

Use a negative value on spread-radius (4th value) to shrink the shadow. This can hide the unwanted top and bottom shadow.

box-shadow: inset 25px 0px 25px -25px rgba(0,0,0,0.45), inset -25px 0px 25px -25px rgba(0,0,0,0.45);

See DEMO.

like image 154
Antony Avatar answered Oct 16 '22 21:10

Antony