So I’m trying to create a responsive frame with inverted corners for my website. I achieved to create the shape of it but once I try to add border to it, -webkit-mask cuts it out. Is there any way to achieve this easily?
.box {
width: 98%;
height: 800px;
-webkit-mask: radial-gradient(40px at 40px 40px,#0000 98%,#000) -40px -40px;
background-color: black;
margin: auto;
border-width: 10px;
border-style: solid;
border-color: red;
}
<div class="box">
</div>
Thank you
Create a border frame with inverted corners and transparent background.
3
Answers
Just reverse your thinking. Rather than adding border after the mask is applied, put some red circles in the corners before applying the mask. Create a background with a similar repeating radial gradient to what you’re using for the mask.
Note that by default, the origin of a mask is
border-box
and the origin of a background ispadding-box
. In this case we want these origins to coincide, so we explicitly set the background origin toborder-box
.You may also put a second div inside the first and apply the same mask. Both can have a different background color and a padding on the parent will visually fake the border: example below:
You don’t need mask for this. Play with gradients and background:
And in case you need use mask, here is another idea:
And if you want a transparent background and any kind of border, then use my online generator to get such shape https://css-generators.com/custom-corners/
I am applying the shape to a pseudo-element so you can put content inside it. If you don’t need content, apply the CSS to the element