Come on, for that you can use the properties border-left-width
and border-right-width
.
See a similar example you want:
.triangle {
width: 0;
height: 0;
border: 0 solid transparent;
border-left-width: 230px;
border-right-width: 242px;
border-top: 39px solid black;
}
<div class="triangle"></div>
Now we need to understand what is happening to div
and how the property works.
The border-left-width
and border-right-width
are equal, only changes the side you set the size. See a small example of how they work:
.show-example {
/* Auxiliar */
background-color: black;
width: 20rem;
height: 5rem;
border: 0 solid #dc143c;
/* O que interessa */
border-right-width: 2em;
border-left-width: 2em;
}
<div class="show-example"></div>
The properties set the value of the side width, and work in partnership with the border-top
, defining the height of the div
. Also remember that the values of the lateral width should be proportional, the height is relative to the size of your triangle.
Note: support for the triangle made with CSS is practically global, since we use well-known tags that have support in virtually all browsers, even in IE, version 4 onwards.
Hugo ball show, I liked the example :)
– João Pedro Schmitz
@Joãopedroschmitz your explanation got very good tb, I always find it confusing to make triangles with edges :D. The advantage of this method is with respect to bg-image, but in the case of a solid color in the background the edge gambit works quietly
– hugocsl
Thanks! That’s right, the problem of border is the same background image!
– João Pedro Schmitz
Thanks a lot, it helped a lot!
– Bruno Folle