Detailed explanation of the use of the clip-path property in CSS

Detailed explanation of the use of the clip-path property in CSS

Use of clip-path

polygon

  • The value is composed of multiple coordinate points. The first value is in the x direction and the second value is in the y direction.
  • The upper left corner is the origin, and the lower right corner is the point (100%, 100%). </p>
body {
  background-color: #000;
}

.fa {
  border: 1px solid #fff;
  color:yellowgreen;
  padding: 10px;
  margin: 10px;
}

.fa>div {
  width: 110px;
  height: 110px;
  background-color: yellowgreen;
  margin: 20px auto;
}

.polygon1 {
  clip-path: polygon(50% 0px, 100% 100%, 0px 100%)
}

.polygon2 {
  clip-path: polygon(0px 50%, 50% 0, 100% 50%, 50% 100%)
}

.polygon3 {
  clip-path: polygon(0% 60%, 20% 0%, 60% 0%, 40% 60%)
}
<div class="fa">
  <p>polygon</p>
  <p>The value is composed of multiple coordinate points. The first value is in the x direction, and the second value is in the y direction. </p>
  <p>The upper left corner is the origin, and the lower right corner is the point (100%, 100%). </p>
  <div class="polygon1"></div>
  <div class="polygon2"></div>
  <div class="polygon3"></div>
</div> 

circle

  • The value consists of a coordinate point and a radius.
  • The upper left corner is the origin, and the lower right corner is the point (100%, 100%).
  • When defining the radius, you can use the at keyword to define the coordinates.
body {
  background-color: #000;
}

.fa {
  border: 1px solid #fff;
  color:yellowgreen;
  padding: 10px;
  margin: 10px;
}

.fa>div {
  width: 110px;
  height: 110px;
  background-color: yellowgreen;
  margin: 20px auto;
}

.circle1 {
  clip-path: circle(50% at 50% 50%)
}

.circle2 {
  clip-path: circle(70% at 50% 50%)
}

.circle3 {
  clip-path: circle(30% at 10% 10%)
}
<div class="fa">
  <p>circle</p>
  <p>The value consists of a coordinate point and a radius. </p>
  <p>The upper left corner is the origin, and the lower right corner is the point (100%, 100%). </p>
  <p>When defining the radius, you can use the at keyword to define the coordinates. </p>
  <div class="circle1"></div>
  <div class="circle2"></div>
  <div class="circle3"></div>
</div> 

ellipse

  • The value consists of the x-axis radius of the ellipse, the y-axis radius, and the coordinates of the positioning ellipse.
  • The upper left corner is the origin, and the lower right corner is the point (100%, 100%).
  • The at keyword separates the radius from the coordinates.
body {
  background-color: #000;
}

.fa {
  border: 1px solid #fff;
  color:yellowgreen;
  padding: 10px;
  margin: 10px;
}

.fa>div {
  width: 110px;
  height: 110px;
  background-color: yellowgreen;
  margin: 20px auto;
}

.ellipse1 {
  clip-path: ellipse(30% 20% at 50% 50%)
}

.ellipse2 {
  clip-path: ellipse(20% 30% at 50% 50%)
}

.ellipse3 {
  clip-path: ellipse(60% 10% at 10% 10%)
}
<div class="fa">
  <p>ellipse</p>
  <p>The value consists of the x-axis radius of the ellipse, the y-axis radius, and the coordinates of the positioning ellipse. </p>
  <p>The upper left corner is the origin, and the lower right corner is the point (100%, 100%). </p>
  <p>The at keyword separates the radius from the coordinates</p>
  <div class="ellipse1"></div>
  <div class="ellipse2"></div>
  <div class="ellipse3"></div>
</div>

inset

The value is (top right bottom left round top left radius top right radius bottom right radius bottom left radius)

The value before round represents the distance. If the first value is 25%, it means that the image is drawn starting from 25% on the top.

body {
  background-color: #000;
}

.fa {
  border: 1px solid #fff;
  color:yellowgreen;
  padding: 10px;
  margin: 10px;
}

.fa>div {
  width: 110px;
  height: 110px;
  background-color: yellowgreen;
  margin: 20px auto;
}

.inset1 {
  clip-path: inset(25% 0% 25% 0% round 0% 25% 0% 25%)
}

.inset2 {
  clip-path: inset(0% 25% 25% 0% round 25% 25% 25% 0%)
}

.inset3 {
  clip-path: inset(25% 25% 0% 0% round 0% 25% 0% 25%)
}
<div class="fa">
  <p>inset</p>
  <p>The value is (top right bottom left round top left radius top right radius bottom right radius bottom left radius)</p>
  <p>The value before round indicates the distance. If the first value is 25%, it means that the image is drawn starting from 25% on the top</p>
  <div class="inset1"></div>
  <div class="inset2"></div>
  <div class="inset3"></div>
</div> 

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  How to use cursor triggers in MySQL

>>:  Master the commonly used HTML tags for quoting content in web pages

Recommend

MySql5.7.21 installation points record notes

The downloaded version is the Zip decompression v...

Implementation of CSS circular hollowing (coupon background image)

This article mainly introduces CSS circular hollo...

How to solve the element movement caused by hover-generated border

Preface Sometimes when hover pseudo-class adds a ...

Native JS encapsulation vue Tab switching effect

This article example shares the specific code of ...

Analyze Tomcat architecture principles to architecture design

Table of contents 1. Learning Objectives 1.1. Mas...

Some parameter descriptions of text input boxes in web design

<br />In general guestbooks, forums and othe...

A pitfall and solution of using fileReader

Table of contents A pitfall about fileReader File...

13 JavaScript one-liners that will make you look like an expert

Table of contents 1. Get a random Boolean value (...

Kali Linux Vmware virtual machine installation (illustration and text)

Preparation: 1. Install VMware workstation softwa...

Detailed explanation of JavaScript program loop structure

Table of contents Select Structure Loop Structure...

Summary of tips for making web pages

Preface This article mainly summarizes some of th...

How to use nginx to simulate blue-green deployment

This article introduces blue-green deployment and...

WeChat applet realizes chat room function

This article shares the specific code of WeChat a...

Example code for hiding element scrollbars using CSS

How can I hide the scrollbars while still being a...

Several common redirection connection example codes in html

Copy code The code is as follows: window.location...