【css】实现一张折扣券

第一种实现方式

使用flex布局实现文本水平垂直居中。

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>demo</title>
    <style>
    .ticket{
        display: flex;
    }
    .left,.middle,.right{
        height: 100px;
    }
    .left{
        width: 100px;
        background: blanchedalmond url(./images/icon_ticket_2.png) no-repeat center;
        border-bottom-right-radius: 50px;
        box-shadow: 50px 0 0 coral ;
    }
    .middle{
        width: 300px;
        background-color: coral;
        color: white;
        font-size: 36px;
        display: flex;
        align-items: center;
        justify-content: space-evenly;
        border-radius: 6px;
        border-right: 2px dashed white;
    }
    .discount{
        font-size: 48px;
        font-weight: bolder;
    }
    .wrapper{
        display: flex;
        align-items: center;
    }
    .right{
        width: 120px;
        background-color: coral;
        display: flex;
        align-items: center;
        justify-content: space-around;
        font-size: 36px;
        color: white;
        border-radius: 6px;
    }
    </style>
</head>
<body>
    <div class="ticket">
        <div class="left"></div>
        <div class="middle">
            <span class="wrapper">
                <span class="discount">5.2</span><span class="text"></span>
            </span>
            <span>商品券</span>
        </div>
        <div class="right">
            <span></span>
        </div>
    </div>
</body>
</html>

在这里插入图片描述

第二种实现方式

使用 text-align:center 实现文本的水平居中;
使用 hight等于line-heightvertical-align:top实现文本的垂直居中。

<!-- test.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>demo</title>
    <style>
    div{
        float: left;
    }
    .left{
        width: 100px;
        height: 100px;
        background: blanchedalmond url(./images/icon_ticket_2.png) no-repeat center;
        border-bottom-right-radius: 50px;
        box-shadow: 50px 0 0 coral ;
    }
    .middle{
        width: 300px;
        height: 100px;
        line-height: 100px;
        text-align: center;
        background-color: coral;
        color: white;
        font-size: 36px;
        border-radius: 6px;
        border-right: 2px dashed white;
    }
    .discount{
        font-size: 48px;
        font-weight: bolder;
        vertical-align: top;
    }
    .right{
        width: 120px;
        height: 100px;
        line-height: 100px;
        text-align: center;
        background-color: coral;
        color: white;
        font-size: 36px;
        border-radius: 6px;
    }

    </style>
</head>
<body>
    <div class="ticket">
        <div class="left"></div>
        <div class="middle">
          <span class="discount">5.2</span>折 商品券
        </div>
        <div class="right">
            <span></span>
        </div>
    </div>
</body>
</html>

在这里插入图片描述

改进版的折扣券
radial-gradient()
示例1
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test</title>
    <style>
    div{
        width: 100px;
        height: 100px;
        margin: 10px;
    }
    .box{
        background: orange radial-gradient(white 50px,transparent 0);
    }
    .box2{
        background:orange  radial-gradient(circle at top right,white 50px,transparent 0);
    }
    .box3{
        background: orange radial-gradient(circle at top right,white 10px, transparent 0) top right;
    }
    .box4{
        background: orange radial-gradient(circle at bottom right,white 10px,transparent 0) bottom right;
    }
    .box5{
        background: radial-gradient(circle at bottom right,white 10px,transparent 0) bottom right,
        radial-gradient(circle at top right, white 10px,transparent 0) top right;
        background-color: orange;
    }
    </style>
</head>
<body>
    <div class="box"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box4"></div>
    <div class="box5"></div>
</body>
</html>

在这里插入图片描述

示例2
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test</title>
    <style>
    .left{
        width: 200px;
        height: 100px;
        margin: 10px;
        background: radial-gradient(circle at top right,white 10px,transparent 0) top right,
        radial-gradient(circle at bottom right,white 10px,transparent 0) bottom right;
        background-color: orange;
    }
    .right{
        width: 100px;
        height: 100px;
        margin: 10px;
        background: radial-gradient(circle at top left,white 10px,transparent 0) top left,
        radial-gradient(circle at bottom left,white 10px,transparent 0) bottom left;
        background-color: orange;
    }
    </style>
</head>
<body>
    <div class="left"></div>
    <div class="right"></div>
</body>
</html>

在这里插入图片描述

示例3
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test</title>
    <style>
    .container{
        width: 300px;
        height: 100px;
        background-color: orange;
        display: flex;
    }
    .left{
        width: 60%;
        background: radial-gradient(circle at top right,white 5px,transparent 0) top right,
        radial-gradient(circle at bottom right,white 5px,transparent 0) bottom right;
    }
    .right{
        width: 40%;
        background: radial-gradient(circle at top left,white 5px,transparent 0) top left,
        radial-gradient(circle at bottom left,white 5px, transparent 0) bottom left;
    }
    </style>
</head>
<body>
    <div class="container">
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>
</html>

在这里插入图片描述

示例4
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test</title>
    <style>
    .container{
        width: 300px;
        height: 100px;
        background-color: orange;
        display: flex;
    }
    .left{
        width: 60%;
        background: radial-gradient(circle at top right,white 5px,transparent 0) top right,
        radial-gradient(circle at bottom right,white 5px,transparent 0) bottom right;
    }
    .right{
        width: 40%;
        background: radial-gradient(circle at top left,white 5px,transparent 0) top left,
        radial-gradient(circle at bottom left,white 5px, transparent 0) bottom left;
    }
    .left::after{
        content: "";
        display: block;
        height: 90px;
        margin-top: 5px;
        border-right: 2px dashed white;
    }
    </style>
</head>
<body>
    <div class="container">
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>
</html>

在这里插入图片描述

改进版
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>demo</title>
    <style>
    .ticket{
        display: flex;
    }
    .left,.middle,.right{
        height: 100px;
    }
    .left{
        width: 100px;
        background: blanchedalmond url(./images/icon_ticket_2.png) no-repeat center;
        border-bottom-right-radius: 50px;
        box-shadow: 50px 0 0 coral ;
    }
    .middle{
        width: 300px;
        background: radial-gradient(circle at top right,white 5px,transparent 0) top right,
        radial-gradient(circle at bottom right,white 5px,transparent 0) bottom right;
        background-color: coral;
        color: white;
        font-size: 36px;
        display: flex;
        align-items: center;
        justify-content: space-evenly;
    }
    .discount{
        font-size: 48px;
        font-weight: bolder;
    }
    .wrapper{
        display: flex;
        align-items: center;
    }
    .right{
        width: 120px;
        line-height: 100px;
        text-align: center;
        background: radial-gradient(circle at top left,white 5px,transparent 0) top left,
        radial-gradient(circle at bottom left,white 5px,transparent 0) bottom left;
        background-color: coral;
        font-size: 36px;
        color: white;
        border-radius: 0 6px 6px 0;
        position: relative;
    }
    .right::before{
        position: absolute;
        left: 0;
        content: "";
        height: 90px;
        margin-top: 5px;
        border-left: 2px dashed white;
    }

    </style>
</head>
<body>
    <div class="ticket">
        <div class="left"></div>
        <div class="middle">
            <span class="wrapper">
                <span class="discount">5.2</span><span class="text"></span>
            </span>
            <span>商品券</span>
        </div>
        <div class="right">
            <span></span>
        </div>
    </div>
</body>
</html>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值