【Web前端实操14】利用CSS绘制三角形和梯形

这篇文章介绍了如何利用CSSborder属性来创建正三角形、倒三角形和向右的三角形,通过设置不同的边框样式和透明度实现图形效果。
摘要由CSDN通过智能技术生成

 绘制正三角形

        主要是利用border属性,设置内容区宽高值为0

        将其下边设置为可见,其他边设为透明

        想要倒三角形也是一样,只要设置上边可见,其他边透明即可

代码区:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绘制特殊图形</title>
    <style>
        /*绘制正三角形
        主要是利用border属性,设置内容区宽高值为0
        将其下边设置为可见,其他边设为透明
        想要倒三角形也是一样,只要设置上边可见,其他边透明即可 */
        .one{
            width: 0;
            height: 0;
            /* border-top: 50px solid red; */
            border-left: 50px solid transparent;
            border-right: 50px solid transparent;  
            border-bottom: 50px solid blue;
            text-align: center;
        }
        /* 绘制梯形
        设置100的宽度 */
        .two{
            width: 100px;
            height: 0;
            border-left: 50px solid transparent;
            border-right: 50px solid transparent;  
            border-bottom: 50px solid rgb(255, 0, 200);
        }
         /*绘制向右的三角形
        主要是利用border属性,设置内容区宽高值为0
        将其左边设置为可见,其他边设为透明
        想要向左三角形也是一样,只要设置右边可见,其他边透明即可 */
        .three{
            width: 0;
            height: 0;
            border-top: 50px solid transparent;
            border-left: 50px solid red;
            border-right: 50px solid transparent;
            border-bottom: 50px solid transparent;
        }
    </style>
</head>
<body>
    <div class="one"></div>
    <br>
    <div class="two"></div>
    <br>
    <div class="three"></div>
</body>
</html>

实现效果:

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值