I am having issues trying to get this to work right. The dropshadows overlap each other, and for some reason the subShape div top needs to be top:-1px to align properly with the top of the mainShape. In my actual project, the mainShape size may change dynamically in height/width. I just always want the subShape to always be on the top-right.
Any suggestions?
Here is link to my codepen: https://codepen.io/coderm3/pen/pvvXdQb
* {
box-sizing: border-box;
}
.mainShape {
position: relative;
width: 200px;
height: 100px;
margin: 15px;
background: white;
padding: 5px;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
border: 1px solid blue;
}
.subShape {
position: absolute;
top: 0px;
right: -60px;
width: 60px;
height: 30px;
padding: 5px;
background: white;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-top: 1px solid blue;
border-right: 1px solid blue;
border-bottom: 1px solid blue;
}
.mainShape:after, .subShape:after {
content:"";
display:block;
position:absolute;
left:0;
top:0;
height: 100%;
width: 100%;
border-radius: 10px;
box-shadow: 0px 0px 10px 10px rgba(0, 0, 0, 0.46);
z-index:-1;
}
<div class="mainShape">
Text in main shape
<div class="subShape">
stuff
</div>
<!-- SVG drop shadow using css3: https://stackoverflow.com/a/6094674/2209007 -->
</div>
you need to reset an offset position from top
equal to the border's width, and you may use a drop-shadow()
filter
to avoid shadows overlapping.
A css var()
can be used to easely reset the border size and offset position
* {
box-sizing: border-box;
}
:root {
--border-size: 1px;
}
.mainShape {
position: relative;
width: 200px;
height: 100px;
margin: 15px;
background: white;
padding: 5px;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
border: var(--border-size) solid blue;
}
.subShape {
position: absolute;
top: calc(var(--border-size) * -1);
right: -60px;
width: 60px;
height: 30px;
padding: 5px;
background: white;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-top: 1px solid blue;
border-right: 1px solid blue;
border-bottom: 1px solid blue;
}
.mainShape {
filter:drop-shadow(0 0 5px);
}
<div class="mainShape">
Text in main shape
<div class="subShape">
stuff
</div>
<!-- SVG drop shadow using css3: https://stackoverflow.com/a/6094674/2209007 -->
</div>
Ressources used: