Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove right side of box shadow

Tags:

html

css

I have found lots of posts similar to what I am asking and have been working away at this for hours and finally decided I should probably seek some exterior advice :).

I am trying to shadow 3 sides of an div using box-shadow I want the right side to be shadowless but cannot figure it out there are lots of posts on how to un-shadow the top but after countless efforts i could not even apply this.

like image 603
Otis Wright Avatar asked Dec 28 '12 09:12

Otis Wright


People also ask

How do you remove a right shadow box?

1) Set your shadow's horizontal alignment to the left (negative values). box-shadow: -30px 0px 10px 10px #888888; Although this way you won't have the same shadow size in the top and bottom. 2) Use a div inside a div and apply shadow to each one.

How do you box shadow left and right?

Simply apply the following CSS to the element in question: box-shadow: 0 0 Xpx Ypx [hex/rgba]; /* note 0 offset values */ clip-path: inset(Apx Bpx Cpx Dpx); Where: Apx sets the shadow visibility for the top edge.

How do you get rid of shadows on the bottom of a box?

Not possible, because box-shadow is generated based on the entire boundary of the element — you can't select which boundaries you don't want the shadow to be computed... unless you are willing to set a negative offset on the y-axis.

How do you put a box shadow on the right side?

box-shadow: h-offset v-offset blur spread color; box-shadows values: h-offset: It is required and used to set the position of the shadow horizontally. The positive value is used to set the shadow on right side of the box and a negative value is used to set the shadow on the left side of the box.


1 Answers

Update:

clip-path is now (2020) supported in all major browsers.


Original Answer:

If you're willing to use experimental technology with only partial support, you could use the clip path property.

This will provide you with exactly the effect I believe you are after: a normal box shadow on the top, left and bottom edges and clean cut-off on the right edge. A lot of other SO solutions to this issue result in shadows that "dissipate" as they near the edge that is to have no shadow.

In your case you would use clip-path: inset(px px px px); where the pixel values are calculated from the edge in question (see below).

#container {     box-shadow: 0 0 5px rgba(0,0,0,0.8);     clip-path: inset(-5px 0px -5px -5px); } 

This will clip the div in question at:

  • 5 pixels above the top edge (to include the shadow)
  • 0 pixels from the right edge (to hide the shadow)
  • 5 pixels below the bottom edge (to include the shadow)
  • 5 pixels outside of the left edge (to include the shadow)

Note that no commas are required between pixel values.

The size of the div can be flexible.

like image 92
Luke Avatar answered Oct 03 '22 18:10

Luke