Home > Article > Web Front-end > How to achieve triangle border effect in css3
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.
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>
Output result:
(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!