BentoumiTech
BentoumiTech

Reputation: 1683

Box with inside curve

I've been trying to create a an 'inside curved box' with no success, I don't seem to find any example online. Can anyone help me to replicate that using just CSS or maybe SVG?

enter image description here

Upvotes: 2

Views: 643

Answers (1)

Harry
Harry

Reputation: 89760

Given that the shape background is a solid color and the page background is not, you can create the shape using a pseudo-element and a box-shadow with high spread radius. Its a hackish solution but would work on most browsers as box shadow has good support.

div{
  position: relative;
  height: 300px;
  width: 150px;
  border-radius: 12px;
  overflow: hidden;
}
div:after{
  position: absolute;
  content: '';
  height: 30px;
  bottom: -15px;
  width: 100%;
  left: 0px;
  box-shadow: 0px 0px 0px 500px blue;
  border-radius: 12px;
}

body{
  background: linear-gradient(chocolate, brown);
  height: 100vh;
}
<div class='shape'></div>


You can also achieve the same effect using SVG path elements like in the below snippet.

div {
  height: 300px;
  width: 150px;
}
svg path {
  fill: blue;
}
body {
  background: linear-gradient(chocolate, brown);
  height: 100vh;
}
<svg viewBox='0 0 150 300' height='0' width='0'>
  <defs>
    <g id='shape'>
      <path d='M0,12 A12,12 0 0,1 12,0 L138,0 A12,12 0 0,1 150,12 L150,300 A12,12 0 0,0 138,288 L12,288 A12,12 0 0,0 0,300z' id='fill' />
    </g>
  </defs>
</svg>

<div class='shape'>
  <svg viewBox='0 0 150 300' preserveAspectRatio='none' vector-effect='non-scaling-stroke'>
    <use xlink:href='#shape' />
  </svg>
</div>

Upvotes: 8

Related Questions