自学前端第一天----画三角形,并使用定位完成前端页面三角动态

.box1{       

        width: 0px;

        height: 0px;

        border-top: 20px solid red;

        border-left: 20px solid yellow;

        border-right: 20px solid blue;

        border-bottom: 20px solid pink;

    }

 

<body>

    <div class="box1"></div>

</body>

将不需要的部分变为透明色就会得到一个三角形

/* 将不需要的部分变透明有三种方法

        1、将不需要的部分的颜色变为和底色一致

        2、利用rgb(0,0,0,透明度)去设置

        3、利用transparent去设置会变成和底色一致的颜色 */

.box2{

        width: 0px;

        height: 0px;

        /* border-top: 20px solid transparent;

        border-left: 20px solid transparent;

        border-right: 20px solid transparent;

        border-bottom: 20px solid blue; */

        /* 可以简写成 */

        border: 20px solid transparent;

        border-bottom: 20px solid blue;

    }

即可得到一个蓝色的上三角

利用三角案例完成前端界面中下拉栏三角的案例

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>三角案例</title>

</head>

<style>

    .box{

        width: 100px;

        height: 50px;

        line-height: 50px;

        text-indent: 10px;

        background-color: pink;

    }

    span{

        width: 0px;

        height: 0px;

        display: inline-block;

        border: 5px solid transparent;

        border-bottom: 5px solid black;

        position: relative;//使用定位将原先的三角形移动至居中位置

        top:-2.5px;

    }

    .box:hover span{

        border: 5px solid transparent;

        border-top: 5px solid black;

        position: relative;

        top:2.5px;

    }

</style>

<body>

    <div class="box">

        前端教程

        <span></span>

    </div>

</body>

</html>

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值