css triangle approach (quick start)

Four triangles

effect:

Effect picture

style:

 .angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            border-top: 20px solid pink;
            border-right: 20px solid red;
            border-left: 20px solid blue;
            border-bottom: 20px solid orange;
        }

Code:

<!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>
        *{
    
    
            margin: 0;
            padding: 0;
        }
        .angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            border-top: 20px solid pink;
            border-right: 20px solid red;
            border-left: 20px solid blue;
            border-bottom: 20px solid orange;
        }
    </style>
</head>
<body>
    <div class="angle"></div>
</body>
</html>

Left triangle

effect:

Triangle picture on the left

style:

 .angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            /* 四个边框设置为透明 */
            border: 20px solid transparent;
            /* 左侧设置边框样式 */
            border-left: 20px solid red;
        }

Code:

<!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>
        *{
    
    
            margin: 0;
            padding: 0;
        }
        .angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            /* 四个边框设置为透明 */
            border: 20px solid transparent;
            /* 左侧设置边框样式 */
            border-left: 20px solid red;
        }
    </style>
</head>
<body>
    <div class="angle"></div>
</body>
</html>

Right triangle

effect:

Right triangle

style:

.angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            /* 四个边框设置为透明 */
            border: 20px solid transparent;
            /* 右侧设置边框样式 */
            border-right: 20px solid blue;
        }

Code:

<!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>
        *{
    
    
            margin: 0;
            padding: 0;
        }
        .angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            /* 四个边框设置为透明 */
            border: 20px solid transparent;
            /* 右侧设置边框样式 */
            border-right: 20px solid blue;
        }
    </style>
</head>
<body>
    <div class="angle"></div>
</body>
</html>

Upper triangle

effect:

Upper triangle

style:

 .angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            /* 四个边框设置为透明 */
            border: 20px solid transparent;
            /* 上边设置边框样式 */
            border-top: 20px solid orange;
        }

Code:

<!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>
        *{
    
    
            margin: 0;
            padding: 0;
        }
        .angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            /* 四个边框设置为透明 */
            border: 20px solid transparent;
            /* 上边设置边框样式 */
            border-top: 20px solid orange;
        }
    </style>
</head>
<body>
    <div class="angle"></div>
</body>
</html>

Lower triangle

effect:

Lower triangle

style:

.angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            /* 四个边框设置为透明 */
            border: 20px solid transparent;
            /* 下边设置边框样式 */
            border-bottom: 20px solid pink;
        }

Code:

在这里插入代码片<!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>
        *{
    
    
            margin: 0;
            padding: 0;
        }
        .angle{
    
    
            margin: 100px auto;
            width: 0;
            height: 0;
            /* 四个边框设置为透明 */
            border: 20px solid transparent;
            /* 下边设置边框样式 */
            border-bottom: 20px solid pink;
        }
    </style>
</head>
<body>
    <div class="angle"></div>
</body>
</html>

note:

  1. width:0 width is 0
  2. height: 0 height is 0
  3. Style the border

Guess you like

Origin blog.csdn.net/yrfjygb/article/details/113687880