Home > Article > Web Front-end > How to write triangle code in css
Writing method: 1. Use the "border: length value solid transparent" statement to set the border of a div element with a width and height of 0 to transparent; 2. Use the "border-top: height value solid color value" statement to set the border of a div element with a width and height of 0 to transparent. When the upper border of the div element's transparent border is displayed, a lower triangle is displayed.
The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.
How to write css lower triangle code
In css, we can create a border style through the border attribute to realize the lower triangle.
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.
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> div{ width: 0; height: 0; border: 100px solid transparent; border-top: 100px solid red; } </style> </head> <body> <div></div> </body> </html>
Output result:
If you are interested, you can continue to visit:css video tutorial.
The above is the detailed content of How to write triangle code in css. For more information, please follow other related articles on the PHP Chinese website!