0

I am trying to clip out a concave edge on the right side of a div (to make a curving sidebar, ultimately). I have struggled with CSS to make this happen.

I got quite close by wrapping the rest of the content in a div with border-radius-top-left and border-radius-bottom-left, creating the illusion of a curving sidebar:

.contentMask {
  margin-left: 12%;
  border-top-left-radius: 12% 50%;
  border-bottom-left-radius: 11% 47%;
}

enter image description here

The result, however, does not follow a curve in the manner i desire - it's more like an ellipse with a very flat edge. I can't get it right. Is there a way to create a sidebar like this, following an arc I can define?

Edit for posterity: I got a bit closer to what I wanted by an additional hack. I made the content taller than the screen with extra vertical space, then used negative top margin to scroll it back into place. Then I made the outer container of the whole thing height: 100vh and overflow: hidden, thus allowing me to basically clip off part of the curve and achieve the arc I wanted. Only problem now is I can't really add box-shadow this way.

enter image description here

temporary_user_name
  • 35,956
  • 47
  • 141
  • 220

3 Answers3

0

The below code might helpful for your situation using background-image property.

div {
   height: 200px;
   width: 200px;
   background-color: green;
   background-image: radial-gradient(45% 75% at 100% 50%, red 75%, transparent 75%);
}

Also you can use clip-path property like below but the curvature might need more points to make like a perfect curve

clip-path: polygon(50% 0%, 100% 0, 84% 36%, 84% 65%, 100% 100%, 50% 100%, 0 100%, 0% 70%, 0% 35%, 0 0);

check the fiddle to see how it works

0

Hello to make a concave side of a div, yes, you can do it using gradient, of course the div will still be square or rectangular. Look at the following example, it is based on this post Border corner shape scoop doesn't work

div {
  height: 200px;
  width: 200px;
  background-color: green;
  background: -webkit-radial-gradient(
      100% 50%,
      circle,
      transparent 45%,
      steelblue 15%
    )
    no-repeat;
  background-position: 0px, 0px;
}
<div>
</div>
Usiel
  • 671
  • 3
  • 14
-1

You could try using clipping path and something like https://bennettfeely.com/clippy/ but I don't think it will work out how you want. Your best bet would probably be to create the image as a background then use display flex or fixed depending on how you want to use it. Or if you want the content to follow the shape maybe even a combination of the two, not sure how that would work out.

html, body {margin: 0; padding: 0;}
section {
  display: flex;
}

nav {
  height: 100vh;
  width: 20vw;
  background-image: url(https://i.postimg.cc/vHC8KpjC/test.png);
  background-size: 100% 100%;
}
ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
<section>
  <nav>
    <ul>
      <li><a href="#">link</a></li>
      <li><a href="#">link</a></li>
      <li><a href="#">link</a></li>
      <li><a href="#">link</a></li>
      <li><a href="#">link</a></li>
    </ul>
  </nav>
  <main>Main content</main>
</section>
KJEK-Code
  • 695
  • 1
  • 5
  • 10