css三角形

 制作css的三角形,方向可以改,如果想朝向上方就消除border-top。

<title>用纯css创建一个三角形</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        
        #box {
            width: 0;
            height: 0;
            border-bottom: 200px solid red;
            /* border-top: 200px solid green; */
            border-left: 200px solid transparent;
            border-right: 200px solid transparent;
        }
    </style>
</head>

<body>
    <div id="box"></div>
</body>
<script>
    window.onload = function() {
        var box = document.getElementById('box');
    }
</script>

如果将左右不改transparent的话就是下面图形。transparent属性设置透明度。上面三角形是旁边透明状态 。不要设计为白色。​​​

 

   #box {
            width: 0;
            height: 0;
            border-bottom: 200px solid red;
            /* border-top: 200px solid green; */
            border-left: 200px solid pink;
            border-right: 200px solid black;
        }

如果设计为白色。也是三角形。但是如果背景有颜色就会不一样的效果。

 body {
            background-color: blue;
        }
        
        #box {
            width: 0;
            height: 0;
            border-bottom: 200px solid red;
            /* border-top: 200px solid green; */
            border-left: 200px solid white;
            border-right: 200px solid white;
        }

 

 

如果每一条边都存在,有颜色。

 #box {
            width: 0;
            height: 0;
            border-bottom: 200px solid red;
            border-top: 200px solid green;
            border-left: 200px solid pink;
            border-right: 200px solid black;
        }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值