Home > Web Front-end > CSS Tutorial > How to achieve triangle border effect in css3

How to achieve triangle border effect in css3

WBOY
Release: 2021-12-16 10:33:21
Original
6680 people have browsed it

Method: 1. Use the statement "border: length value solid transparent; border-top: height value solid color value" to set the empty element to a triangle style; 2. Place small triangle elements in different colors Within the large triangle element, you can achieve the effect of a triangle with a border.

How to achieve triangle border effect in css3

The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.

How to achieve the effect of triangle with border in css3

In css, if you want to achieve the effect of triangle with border, you need to use the border attribute.

First we need a div element with a width and height of 0, then use the border attribute to set the border style of the div, set the thickness value of the border to half the length of the lower triangle, and set the border color to transparent color.

Finally, display the top border of the div element through the border-top attribute.

Placing small triangle elements inside large triangle elements of different colors can achieve the effect of triangles with borders.

The example is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #demo {
            width: 0;
            height: 0;
            position: relative;
            border-top: solid 50px transparent;
            border-right: solid 50px black;
            /* 黑色大三角形 */
            border-bottom: solid 50px transparent;
        }
 
        #demo:after {
            content: "";
            width: 0;
            height: 0;
            position: absolute;
            left: 3px;
            top: -45px;
            border-top: solid 45px transparent;
            border-right: solid 45px white;
            /* 白色小三角形 */
            border-bottom: solid 45px transparent;
        }
</style>
</head>
<body>
<div id="demo"></div>
</body>
</html>
Copy after login

Output result:

How to achieve triangle border effect in css3

(Learning video sharing: css video tutorial)

The above is the detailed content of How to achieve triangle border effect in css3. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template