A triangle in CSS is a hack created by displaying parts of the border of an element. Therefore, the triangle that you see is not the element itself, but the CSS border.
A border cannot be styled using the usual CSS background-image style, and it is here that you begin to see the limitations of CSS triangles and why this is really a hack and not a good technique.
There is a CSS solution that might work for you: border-image .
border-image is a CSS style that does what you expect; it puts the image on the border of the element. Since the CSS triangle is a border, you can use it to place a background image on your triangle.
However, things get complicated. The border-image style is for border styles, not triangles; It has functions for laying corners and sides, as well as stretching images accordingly. I have not tried it with a triangle, but I can predict that it may have some quirks that make it difficult to use. But feel free to let him go.
Another problem with border-image is browser support. This is a relatively new CSS style and is not fully supported in many modern browsers, including all versions of IE. You can see the full browser support table for it CanIUse .
Because of all these issues, I would suggest that if you want to draw shapes in a browser, you really should consider removing CSS hackers and using SVG or Canvas. They are well supported in most browsers and obviously support all of the drawing features you might want.
CSS triangles are great for creating a random arrow shape, but for something more complex than that, it's much easier to use the right graphics, rather than trying to put more and more hacks into your CSS code.
source share