Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw triangles with css

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "how to draw triangles with css". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to draw triangles with css" can help you solve your doubts.

First of all, we know that using a border to achieve a triangle is very simple, directly on the code above.

.triangleTest {

.content div {

Width: 0

Height: 0

& .up {

Border-left: 50px solid transparent

Border-right: 50px solid transparent

Border-bottom: 100px solid red

Border-top: 0

}

}

}

You can see that it is easy to implement a triangle with a styled border-width, but this article will explain in principle why it is shown in this way.

# box {

Width:200px

Height:200px

Background:yellow

Border-top: 80px solid red

Border-right:80px solid black

Border-bottom:80px solid green

Border-left:80px solid blue

}

As you can see, the box is 200px in width and height, and the border is 80px. Due to the different colors of the border, it is obvious that it is trapezoidal to cover the content area (yellow area). If the length or width is less than the maximum border, the content area is not visible (yellow area), which means that when the box length and width is less than 160px (80 + 80), then there are four triangles.

Going back to the first example, it is easy to explain why it is a triangle, because the left and right borders are transparent and cannot be seen, so we can only look at an upward triangle formed by the border at the bottom.

According to the above principle, we can achieve many kinds of triangles and trapezoids.

.left {

Border-left: 50px solid red

Border-top: 50px solid red

Border-right: 50px solid transparent

Border-bottom: 50px solid transparent

}

.right {

Border-left: 50px solid transparent

Border-top: 50px solid transparent

Border-right: 50px solid red

Border-bottom: 50px solid red

}

. bottom-left {

Width: 120px

Height: 120px

Background-color: transparent

Border-left: 50px solid transparent

Border-top: 50px solid transparent

Border-right: 50px solid transparent

Border-bottom: 50px solid red

}

After reading this, the article "how to draw triangles with css" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 264

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report