Home > Web Front-end > CSS Tutorial > Can CSS `clip-path` Round Only Three Left Corners of a Shape?

Can CSS `clip-path` Round Only Three Left Corners of a Shape?

Linda Hamilton
Release: 2024-12-30 05:29:09
Original
198 people have browsed it

Can CSS `clip-path` Round Only Three Left Corners of a Shape?

How to Round Three Left Corners Only Using CSS clip-path

Creating shapes using CSS clip-path can be a versatile way to achieve various designs. However, rounding out specific corners can be challenging. This article addresses the issue of rounding the leftmost three corners of a custom shape.

Problem:
Consider the following HTML and CSS code:

<div></div>

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%);
}
Copy after login

This code creates a shape with sharp left corners and rounded right corners. To specifically round out only the three leftmost corners, we need to modify the clip-path property.

Solution:
To achieve the desired effect, we can utilize the inset() function with the round property:

-webkit-clip-path: inset(0% 45% 0% 45% round 10px);
clip-path: inset(0% 45% 0% 45% round 10px);
Copy after login

The inset() function allows us to specify the percentage of the shape to be hidden in each direction, and the round property creates rounded edges. By providing a radius of 10px to the round property, we round out the top left, bottom left, and lower middle corners.

This solution will effectively create a shape with rounded leftmost three corners while preserving the sharp right corners.

The above is the detailed content of Can CSS `clip-path` Round Only Three Left Corners of a Shape?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template