Home  >  Article  >  Web Front-end  >  How to write triangle code in css

How to write triangle code in css

WBOY
WBOYOriginal
2021-12-10 11:58:185984browse

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.

How to write triangle code in css

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:

How to write triangle code in css

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!

Statement:
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