I am currently working on a Web Project and am facing some issue related to CSS. I need help with finding a Solution (responsive) for the interface elements that I am pasting below.
I have gone through multiple approaches to achieve this using CSS (available across internet) but I am unable to make it work perfectly. Cut Opposite Corners (45 deg. left top and bottom right) – I can do that; One slant greater than the other – I can do that; rounding the remaining two corner (right top and bottom left) – I can do that.
What I am failing at is, rounding the edges of the slant slightly while being able to control the rounding (should be independent) of other two corners (top right and bottom left).
A help in this regard will be highly appreciated!
.box {
position: relative;
border: 10px;
height: 100px;
width: 200px;
padding: 40px 0px 10px 40px;
/* border-radius: 20px; */
}
.box:before {
border-radius: 20px;
content: "";
position: absolute;
inset: 0;
background: #FFCC00;
clip-path: polygon(0 40px,40px 0,100% 0,100% calc(100% - 40px),calc(100% - 40px) 100%,0 100%,0 40px,10px calc(40px + 4.14px),10px calc(100% - 10px),calc(100% - 40px - 4.14px) calc(100% - 10px),calc(100% - 10px) calc(100% - 40px - 4.14px),calc(100% - 10px) 10px,calc(40px + 4.14px) 10px,10px calc(40px + 4.14px));
}
<div class="box">
Hello World!
</div>
2
Answers
I did find a solution using SVG and Gradients here on SO but the limitation I was facing is the independent rounding-off of the opposite corners and also when the box size is small, the slant becomes more rounded and does not appear very neat:
A flexible way to achieve this is using a combination of CSS clip-path, pseudo-elements, and border-radius:
Detailed Explanation:
Hope this helps!