Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

วิธีสร้างสามเหลี่ยมโดยใช้ CSS clip-path


เราสามารถสร้างสามเหลี่ยมโดยใช้คุณสมบัติ CSS คลิปพาธ

ไวยากรณ์

ไวยากรณ์ของคุณสมบัติ CSS คลิปพาธมีดังต่อไปนี้ -

Selector {
   clip-path: /*value*/
}

ตัวอย่าง

ตัวอย่างต่อไปนี้แสดงคุณสมบัติ CSS clip-path คุณสมบัติ

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            padding: 10%;
            border-radius: 2%;
            width: 10%;
            box-shadow: inset 0 0 80px violet;
            clip-path: polygon(50% 0, 100% 100%, 0% 100%);
         }
      </style>
   </head>
   <body>
      <div></div>
   </body>
</html>

ซึ่งจะได้ผลลัพธ์ดังต่อไปนี้

วิธีสร้างสามเหลี่ยมโดยใช้ CSS clip-path

ตัวอย่าง

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            display: flex;
            margin: 10px 0 20px;
         }
         div > div {
            height: 12px;
            border-top: 40px ridge orange;
            border-right: 20px solid white;
            border-bottom: 60px ridge cornflowerblue;
            border-left: 80px solid white;
         }
      </style>
   </head>
   <body>
      <div>
         <div></div>
      </div>
   </body>
</html>

ซึ่งจะได้ผลลัพธ์ดังต่อไปนี้

วิธีสร้างสามเหลี่ยมโดยใช้ CSS clip-path