css绘制三角形

本文分享了一种使用CSS边框属性来绘制三角形的方法,通过调整border宽度和颜色,可以在网页中轻松创建各种大小和颜色的三角形。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  今天,偶遇一个css绘制三角形的代码,用处很大哦,分享给大家,送上代码

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6     <style type="text/css">
 7         .parent{
 8             width: 300px;
 9             height: 100px;
10             margin: 10px auto;
11             background-color: green;
12         }
13         .square{
14             width: 0;
15             height: 0;
16             border-bottom: 15px solid white;
17             border-left: 15px solid white;
18             border-right: 15px solid green;
19             border-top: 15px solid green;
20             position: relative;
21             left: -30px;
22             top: 20px;
23         }
24     </style>
25 </head>
26     <div class="parent">
27         <div class="square"></div>
28     </div>
2
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6     <style type="text/css">
 7         .parent{
 8             width: 300px;
 9             height: 100px;
10             margin: 10px auto;
11             background-color: green;
12         }
13         .square{
14             width: 0;
15             height: 0;
16             border-bottom: 15px solid white;
17             border-left: 15px solid white;
18             border-right: 15px solid green;
19             border-top: 15px solid green;
20             position: relative;
21             left: -30px;
22             top: 20px;
23         }
24     </style>
25 </head>
26     <div class="parent">
27         <div class="square"></div>
28     </div>
29 </html>

 

  我再firefox浏览器上得到如下效果,看官请看:

  把content的区域设置成0*0,然后再利用border属性选取适当的变化就可以了;

转载于:https://www.cnblogs.com/anchao/p/5068380.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值