欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

css三角做法

程序员文章站 2022-05-26 22:22:45
...

发现

当给一个宽度、高度为0的盒子加上四个不同颜色的边框,时发现出现四个三角
css三角做法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            width: 0;
            height: 0;
            /* border: 10px solid pink; */
            border-top: 10px solid pink;
            border-right: 10px solid red;
            border-left: 10px solid green ;
            border-bottom: 10px solid blue;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
</body>
</html>

css三角做法
代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            width: 0;
            height: 0;
            /* border: 10px solid pink; */
            border-top: 10px solid pink;
            border-right: 10px solid red;
            border-left: 10px solid green ;
            border-bottom: 10px solid blue;
        }
        .box2 {
            width: 0;
            height: 0;
            border: 50px solid transparent;
            border-top-color: pink;
            margin: 100px auto;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
</body>
</html>

三角应用-京东效果

css三角做法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            width: 0;
            height: 0;
            /* border: 10px solid pink; */
            border-top: 10px solid pink;
            border-right: 10px solid red;
            border-left: 10px solid green ;
            border-bottom: 10px solid blue;
        }
        .box2 {
            width: 0;
            height: 0;
            border: 50px solid transparent;
            border-top-color: pink;
            margin: 100px auto;
        }
        .jd {
            position: relative;
            width: 120px;
            height: 249px;
            background-color: pink;

        }
        .jd span {
            position: absolute;
            top: -20px;
            left: 70px;
            width: 0;
            height: 0;
            /* 为了照顾兼容性 */
            line-height: 0;
            font-size: 0;
            border: 10px solid transparent;
            border-bottom-color:pink;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="jd">
        <span></span>
    </div>
</body>
</html>
相关标签: css