从前端小白到大佬 三角做法

css 三角

此三角其实是对话框上的小三角形,别急,先看一个效果。
在这里插入图片描述
是不是想要这个效果?然后再看一段代码。

<!doctype html>
<html>

<head>
    <meta charset='UTF-8' />
    <title>damoe</title>
    <style type="text/css">
        .box {
            width: 0;
            height: 0;
            border-bottom: 50px solid aquamarine;
            border-top: 50px solid black;
            border-left: 50px solid blueviolet;
            border-right: 50px solid brown;
            margin: 0 auto;
        }
        
        .box2 {
            width: 0;
            height: 0;
            border: 50px solid transparent;
            border-right: 50px solid red;
            margin: 50px auto;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <div class="box2"></div>
</body>

</html>

效果:
在这里插入图片描述
就是简单的一个盒子,当他的宽度高度为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>
        .box,
        .box2 {
            position: relative;
            width: 120px;
            height: 249px;
            background-color: rosybrown;
            margin: 50px auto;
        }
        
        .box span {
            position: absolute;
            top: -30px;
            left: 10px;
            width: 0;
            height: 0;
            /* 为了照顾兼容性 */
            line-height: 0;
            font-size: 0;
            border: 15px solid transparent;
            border-bottom: 15px solid rosybrown;
        }
        
        .box2 {
            border-radius: 10px;
        }
        
        .box2 span {
            position: absolute;
            top: 15px;
            left: 120px;
            width: 0;
            height: 0;
            /* 为了照顾兼容性 */
            line-height: 0;
            font-size: 0;
            border: 15px solid transparent;
            border-left: 15px solid rosybrown;
        }
    </style>
</head>

<body>
    <div class="box">

        <span></span>
    </div>

    <div class="box2">
        <span></span>
    </div>
</body>

</html>

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值