Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round out corners when using CSS clip-path

Tags:

I want to be able to round out the 3 leftmost corners on this shape that I have created, any idea how that can be done?

div {    position: absolute;    z-index: 1;    width: 423px;    height: 90px;    background-color: #b0102d;    color: white;    right: 0;    margin-top: 10vw;    -webkit-clip-path: polygon(100% 0%, 100% 50%, 100% 100%, 25% 100%, 0% 50%, 25% 0%);    clip-path: polygon(100% 0%, 100% 50%, 100% 100%, 25% 100%, 0% 50%, 25% 0%);  }
<div></div>
like image 249
Eduardo Hernandez Avatar asked Aug 01 '15 19:08

Eduardo Hernandez


People also ask

How do you round clip corners path?

you need to write as many points as possible to round the corner. Nothig else... for, example a few more points to make lower part bit rounder: -webkit-clip-path: polygon(100% 0%, 100% 100%, 100% 100%, 25% 100%, 5% 70%,1% 60%, 0% 50%, 25% 0%);

How do I make rounded corners of an image in CSS?

Style your corners.The border-radius CSS property is what adds the rounded corners. You can experiment with different values to get it the way you like. border-radius: 75px; If you want it to be a circle, add border-radius: 50%; .

How do you make a box have rounded corners CSS?

To create a simple box with rounded corners, add the border-radius property to box1 . The border-radius property is a shorthand property that sets the radius for all four corners of the box to the same value when given only one value.


1 Answers

I've recently found success experimenting with approaches like this...

SVG

<svg width="0" height="0">   <defs>     <clipPath id="clipped">       <circle cx="var(--myRad)" cy="var(--myRad)" r="var(--myRad)"></circle>       <circle cx="var(--myRad)" cy="calc(var(--myHeight) - var(--myRad))" r="var(--myRad)"></circle>       <circle cx="calc(var(--myWidth) - var(--myRad))" cy="calc(var(--myHeight) - var(--myRad))" r="var(--myRad)"></circle>       <circle cx="calc(var(--myWidth) - var(--myRad))" cy="var(--myRad)" r="var(--myRad)"></circle>       <rect y="var(--myRad)" width="var(--myWidth)" height="calc(var(--myHeight) - (2 * var(--myRad)))"></rect>       <rect x="var(--myRad)" width="calc(var(--myWidth) - (2 * var(--myRad)))" height="var(--myHeight)"></rect>     </clipPath>   </defs> </svg> 

CSS

.clipped {   --myWidth: 100vw;   --myHeight: 10rem;   --myRad: 2rem;   clip-path: url(#clipped); } 

I found this useful as compared to using border-radius with overflow set to hidden, because this approach doesn't create a BFC or break things like sticky position and css perspective effects. Also, this allows you to "inset" the position of the svg paths to clip inside the element with a "corner-radius" if you want.

like image 91
jonjohnjohnson Avatar answered Oct 04 '22 06:10

jonjohnjohnson