I’m trying to create a block with a smooth, curved cut-out in the top-right corner, similar to the image below:
Currently, my implementation looks like this:
As you can see, the current curve is not as smooth as I’d like it to be – It’s essentially not a curve, but a square with straight angles. Here’s my current code:
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
.curved-block {
width: 300px;
background-color: white;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
position: relative;
overflow: hidden;
padding: 5px;
}
.curved-block::after {
content: '';
position: absolute;
top: 0;
right: 0;
width: 40px;
height: 40px;
background-color: #f0f0f0;
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cpath d='M0 0 h25 c5 0, 10 0, 13 3 s2 7, 2 12 v25 h-40 z' fill='%23000000'/%3E%3C/svg%3E");
-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cpath d='M0 0 h25 c5 0, 10 0, 13 3 s2 7, 2 12 v25 h-40 z' fill='%23000000'/%3E%3C/svg%3E");
mask-size: cover;
-webkit-mask-size: cover;
}
.icon {
position: absolute;
top: 8px;
right: 8px;
width: 23px;
height: 23px;
display: flex;
justify-content: center;
align-items: center;
font-size: 16px;
font-weight: bold;
background-color: #0056b3;
border-radius: 50%;
color: white;
z-index: 2;
}
<div class="curved-block">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<span class="icon">+</span>
</div>
I’m struggling to achieve a smoother, more natural-looking curve in the SVG mask. How can I modify the SVG path to create a curve that looks more like the one in the desired result image? Thank you in advance for your suggestions.
2
Answers
I did it here: https://css-shape.com/inverted-radius/
You can easily copy the code and adjust the variables:
Since you’re using uniformly rounded corners you may also combine a CSS
clip-path
with a SVG "goo" filter.We’re basically
Unfortunately we need some additional wrapping elements otherwise we can’t apply a drop shadow or the plus-button is also affected by the filters.
Goo filter
You can either reference the filter by inlining a SVG in your HTML
and apply it in CSS like so:
or you can encode the SVG to a dataURL and embed it directly in CSS
The
stdDeviation='7.5'
value specifies the border/rounding radius.See also