-2

I made a div triangle and it is placed perfectly. When I put it in I wanted it to be a different color than grey. So I went back to my class (css) and put background: red and it changed the area around it red not the triangle itself. If you can help it would be appreciated!

.triangle {
  width: 10px;
  height: 0px;
  border-left: 1030px solid transparent;
  border-right: 1030px solid transparent;
  border-bottom: 500px solid #555;
  position: absolute;
  left: -322px;
  top: 160px;
  z-index: -1;
  background: red;
}
<div class="triangle"></div>
Aniket G
  • 3,471
  • 1
  • 13
  • 39

2 Answers2

0

The triangle is made out of a border, so the only way to change the color is to change the border color. The snippet below works.

.triangle {
  width: 10px;
  height: 0px;
  border-left: 1030px solid transparent;
  border-right: 1030px solid transparent;
  border-bottom: 500px solid red;
  position: absolute;
  left: -322px;
  top: 160px;
  z-index: -1;
}
<div class="triangle"></div>
Aniket G
  • 3,471
  • 1
  • 13
  • 39
0

Change the border-bottom instead

border-bottom: 500px solid red;
Leo
  • 14,625
  • 2
  • 37
  • 55