Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS irregular shape, combined with shadow

Tags:

css

flexbox

I want to combine two shapes and their shadows, to create the UI shown below.

In my attempts the shadow of the first element would overlap the second element.

Any ideas how I can make this work, cross browser?

Shadow overlap

HTML

<div class="mainShape">
  <div class="subShape">

  </div>
</div>

CSS

.mainShape {
  position: relative;
  box-shadow: 6px 0 21px -3px rgba(86,93,111,0.12);
  background: white;
  width: 200px;
  height: 600px;
}

.subShape {
  position: absolute;
  top: 0px;
  right: -60px;
  width: 60px;
  height: 180px;
  box-shadow: 6px 0 21px -3px rgba(86,93,111,0.12);
}

https://jsfiddle.net/mk32g7yj/7/

like image 263
Titsjmen Avatar asked Oct 17 '25 09:10

Titsjmen


1 Answers

There may be a more elegant way to do this, such as Sumurai's suggestion of using an svg, but a rather hacky way of achieving this could be to stick a "masking" div (with a white background) up between the two other divs:

.mainShape {
  position: relative;
  box-shadow: 6px 0 21px -3px rgba(86,93,111,0.12);
  background: white;
  width: 200px;
  height: 600px;
}

.subShape {
  position: absolute;
  top: 0px;
  right: -60px;
  width: 60px;
  height: 180px;
  box-shadow: 6px 0 21px -3px rgba(86,93,111,0.12);
}

.mask {
  position: absolute;
  top:0px;
  right:-20px;
  width:25px;
  height:180px;
  background-color:white;
}
<div class="mainShape">
  <div class="subShape">

  </div>
  <div class="mask">
  
  </div>
</div>
like image 149
Michael Beeson Avatar answered Oct 19 '25 01:10

Michael Beeson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!