CSS画三角

一、等边直角三角形

三角案例

 

在网页中我我们会遇到这种三角,我们可以通过css来实现

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<link rel="stylesheet" href="css/iconfont.css">
<script src="js/iconfont.js" ></script>
<style>
    .one{
        width: 0px;
        height: 0px;
        /*考虑兼容性*/
        line-height:0 ;
        font-size: 0;
        border:50px solid;
        border-bottom-color: red;
        border-left-color: yellow;
        border-top-color: blue;
        border-right-color: green;
    }
</style>
<body>
    <div class="one"></div>
</body>
</html>

页面上显示的结果。

所以我们可以通过隐藏其他角来制作三角形

 

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<link rel="stylesheet" href="css/iconfont.css">
<script src="js/iconfont.js" ></script>
<style>
    .one{
        width: 0px;
        height: 0px;
        /*考虑兼容性*/
        line-height:0 ;
        font-size: 0;
        border:50px solid transparent;
        border-top-color: red;
    }
</style>
<body>
    <div class="one"></div>
</body>
</html>

 

 

二、直角三角形

类似于我们做出一个京东秒杀价格的一个示例。

在做这个示例之前我还提前去京东官网(火狐浏览器,其他的都正常)去重新看了一下,发现。。。

不知道是有意为之,还是真的出了错

原理:

核心代码:

 

示例:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<style>
    .price{
        width: 220px;
        height: 30px;
        border: 1px solid red;
        line-height: 30px;
    }
    .pri_miaosha{
        position: relative;
        float: left;
        width: 120px;
        height: 30px;
        font-size: 20px;
        color: white;
        text-align: center;
        background-color: red;
        font-weight: 700;
    }
    .pri_org{
        margin-left: 20px;;
        color:darkgray;
        font-size: 16px;
        text-decoration: line-through;
    }
    .price .pri_miaosha i{
        position: absolute;
        display: inline-block;
        width: 0;
        height: 0;
        line-height: 0;
        font-size: 0;
        border-color:  transparent white transparent transparent;
        border-style: solid;
        border-width: 30px 10px 0 0;
        right: 0px;
    }
</style>
<body>
<div class="price">
    <div class="pri_miaosha">¥1960.00
        <i></i>
    </div>
    <div class="pri_org">¥3560.00</div>
</div>
</body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值