DEV Community

Discussion on: Daily Challenge #52 - Building a Pyramid

Collapse
 
alvaromontoro profile image
Alvaro Montoro

CSS

This is a variation of my solution for challenge #2. Just add the class "triangle" to a block element, and specify the lines in the CSS variable --stars:

.triangle {
  --stars: 10;
  width: calc(2 * var(--stars) * 10px);
  height: calc((var(--stars)) * 15px);
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10px" height="15px" viewBox="0 0 10 15"><text x="5" y="12" fill="black" dominant-baseline="middle" text-anchor="middle">*</text></svg>');
  background-position: top center;
  clip-path: polygon(50% 0, 100% 100%, 0% 100%);
}

The idea is having an inline SVG background with the asterisks, then clipping the shape of the triangle. Here is a demo on Codepen: