Home > database >  how can i display stars in an outline of a circle
how can i display stars in an outline of a circle

Time:04-22

So i have this code, it creates some tiny stars, how can i make them come in order from the left like come one by one and form an outline of a circle in the center of the page, also how can i make the stars like the normal stars with 5 corners, and how can i make the size much bigger.

.stars {
  --num: 10;
  /* the number of stars */
  --w: 50vmin;
  width: var(--w);
  aspect-ratio: 1 / 1;
  position: relative;
  left: 100%;
  /* out of view to start with */
  transition: left 2s;
  color: #FFD700;
}

.stars.show {
  left: 0;
}

.stars>* {
  --starw: calc(var(--w) / var(--num));
  width: var(--starw);
  height: 50%;
  top: 0;
  left: calc(50% - (var(--starw) / 2));
  transform: rotate(calc(var(--n) / var(--num) * 360deg));
  transform-origin: 50% bottom;
  position: absolute;
  text-align: center;
}

.stars>*::after {
  content: '*';
  position: absolute;
  top: 0;
  text-align: center;
  z-index: 1;
  width: 100%;
  left: 0;
  font-size: var(--starw);
}

.stars *:nth-child(1) {
  --n: 1;
}

.stars *:nth-child(2) {
  --n: 2;
}

.stars *:nth-child(3) {
  --n: 3;
}

.stars *:nth-child(4) {
  --n: 4;
}

.stars *:nth-child(5) {
  --n: 5;
}

.stars *:nth-child(6) {
  --n: 6;
}

.stars *:nth-child(7) {
  --n: 7;
}

.stars *:nth-child(8) {
  --n: 8;
}

.stars *:nth-child(9) {
  --n: 9;
}

.stars *:nth-child(10) {
  --n: 10;
}
<button onclick="document.querySelector('.stars').classList.add('show');">CLICK ME</button>
<div >
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>
So i have this code, it creates some tiny stars, how can i make them come in order from the left like come one by one and form an outline of a circle in the center of the page, also how can i make the stars like the normal stars with 5 corners, and how can i make the size much bigger.

CodePudding user response:

You can use:

  • content: '★'; to use the five-point star
  • color: #FFD700; to use your golden color
  • font-size: 2.5rem; to increase the size

Here's a running example:

.stars {
      --num: 10;
      /* the number of stars */
      --w: 50vmin;
      width: var(--w);
      aspect-ratio: 1 / 1;
      position: relative;
      left: 100%;
      /* out of view to start with */
      transition: left 2s;
    }

    .stars.show {
      left: 0;
    }

    .stars>* {
      --starw: calc(var(--w) / var(--num));
      width: var(--starw);
      height: 50%;
      top: 0;
      left: calc(50% - (var(--starw) / 2));
      transform: rotate(calc(var(--n) / var(--num) * 360deg));
      transform-origin: 50% bottom;
      position: absolute;
      text-align: center;
    }

    .stars>*::after {
      content: '★';
      position: absolute;
      top: 0;
      text-align: center;
      z-index: 1;
      width: 100%;
      left: 0;
      font-size: var(--starw);
      color: #FFD700;
      font-size: 1.5rem;
    }

    .stars *:nth-child(1) {
      --n: 1;
    }

    .stars *:nth-child(2) {
      --n: 2;
    }

    .stars *:nth-child(3) {
      --n: 3;
    }

    .stars *:nth-child(4) {
      --n: 4;
    }

    .stars *:nth-child(5) {
      --n: 5;
    }

    .stars *:nth-child(6) {
      --n: 6;
    }

    .stars *:nth-child(7) {
      --n: 7;
    }

    .stars *:nth-child(8) {
      --n: 8;
    }

    .stars *:nth-child(9) {
      --n: 9;
    }

    .stars *:nth-child(10) {
      --n: 10;
    }
    
    <button onclick="document.querySelector('.stars').classList.add('show');">CLICK ME</button>
    <div >
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>

CodePudding user response:

For the color add color: ##FFD700 to stars>* . For the shape, you can use an SVG.

  • Related