纯Css实现三角形、气泡框的三角形

上下左右箭头

效果图片
在这里插入图片描述
HTML

  	<!-- 向上的三角形 -->
    <div class="triangle_border_up"></div>
    <!-- 向下的三角形 -->
    <div class="triangle_border_down"></div>
    <!-- 向左的三角形 -->
    <div class="triangle_border_left"></div>
    <!-- 向右的三角形 -->
    <div class="triangle_border_right"></div>

Css

        /*向上*/
        .triangle_border_up {
            width: 0;
            height: 0;
            border-width: 0 30px 30px;
            border-style: solid;
            border-color: transparent transparent #FFCCCC;
            				/*透明         透明       黄*/
            margin: 40px auto;
            position: relative;
        }

        /*向下*/
        .triangle_border_down {
            width: 0;
            height: 0;
            border-width: 30px 30px 0;
            border-style: solid;
            border-color: #FFCCCC transparent transparent;
            				/*黄 	透明         透明 */
            margin: 40px auto;
            position: relative;
        }

        /*向左*/
        .triangle_border_left {
            width: 0;
            height: 0;
            border-width: 30px 30px 30px 0;
            border-style: solid;
            border-color: transparent #FFCCCC transparent transparent;
            				/*透明       黄   透明        透明 */
            margin: 40px auto;
            position: relative;
        }

        /*向右*/
        .triangle_border_right {
            width: 0;
            height: 0;
            border-width: 30px 0 30px 30px;
            border-style: solid;
            border-color: transparent transparent transparent #FFCCCC;
            				/*透明       透明        透明         黄*/
            margin: 40px auto;
            position: relative;
        }

左上、左下、右上、右下箭头

效果图片
在这里插入图片描述
HTML

 	<!-- 左上 -->
    <div class="triangle_border_nw"></div>
    <!-- 左下 -->
    <div class="triangle_border_sw"></div>
    <!-- 右上 -->
    <div class="triangle_border_ne"></div>
    <!-- 右下 -->
    <div class="triangle_border_se"></div>

Css

        /* 左上 */
        .triangle_border_nw {
            width: 0;
            height: 0;
            border-width: 30px 30px 0 0;
            border-style: solid;
            border-color: #CCCCFF transparent transparent transparent;
            margin: 40px auto;
            position: relative;
        }

        /* 左下 */
        .triangle_border_sw {
            width: 0;
            height: 0;
            border-width: 30px 0 0 30px;
            border-style: solid;
            border-color: transparent transparent transparent #CCCCFF;
            margin: 40px auto;
            position: relative;
        }

        /* 右上  */
        .triangle_border_ne {
            width: 0;
            height: 0;
            border-width: 30px 0 0 30px;
            border-style: solid;
            border-color: #CCCCFF transparent transparent transparent;
            margin: 40px auto;
            position: relative;
        }

        /* 右下 */
        .triangle_border_se {
            width: 0;
            height: 0;
            border-width: 30px 30px 0 0;
            border-style: solid;
            border-color: transparent #CCCCFF transparent transparent;
            margin: 40px auto;
            position: relative;
        }

气泡框的三角形

效果图片
在这里插入图片描述
HTML

 	<div class="test_triangle_border">
        <div class="popup">
            纯CSS写带边框的三角形
        </div>
    </div>

Css

		.test_triangle_border {
            width: 200px;
            margin: 0 auto 20px;
            position: relative;
        }

        .test_triangle_border .popup {
            width: 100px;
            background: #99FF99;
            padding: 10px 20px;
            color: #333;
            border-radius: 4px;
            position: absolute;
            top: 30px;
            left: 30px;
            border: 1px solid #333;
        }

        .test_triangle_border .popup::before {
            content: '';
            width: 0px;
            height: 0px;
            border-width: 0 10px 10px;
            border-style: solid;
            border-color: transparent transparent #333;
            left: 50%;
            top: -10px;
            position: absolute;
            margin-left: -10px;
        }

        .test_triangle_border .popup::after {
            content: '';
            width: 0px;
            height: 0px;
            border-width: 0 10px 10px;
            border-style: solid;
            border-color: transparent transparent #99FF99;
            left: 50%;
            top: -9px;
            position: absolute;
            margin-left: -10px;
        }
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值