1

How can I condense this many span tags? I am trying to get it as small as possible. Any advice helps, thanks!

<header>
<a href="#" class="loo">cat <i class="fa-d fa-ct"></i></a>>
<div class="particle">
  <span style="--i:50;"></span>
  <span style="--i:21;"></span>
  <span style="--i:16;"></span>
  <span style="--i:18;"></span>
  <span style="--i:13;"></span>
  <span style="--i:22;"></span>
  <span style="--i:15;"></span>
  <span style="--i:24;"></span>
  <span style="--i:17;"></span>
  <span style="--i:28;"></span>
  <span style="--i:12;"></span>
  <span style="--i:26;"></span>
  <span style="--i:23;"></span>
  <span style="--i:13;"></span>
  <span style="--i:17;"></span>
  <span style="--i:11;"></span>
  <span style="--i:21;"></span>
  <span style="--i:16;"></span>
</div>
</div>

This is why I am trying to get. Each --i:Number creates a particle at random times.

enter image description here

3
  • 1
    What do you mean by condence? Commented Dec 30, 2022 at 19:34
  • can't you just have 1 span element and clone it? Commented Dec 30, 2022 at 19:36
  • How are the spans currently generated? Commented Dec 30, 2022 at 19:41

1 Answer 1

1

In case you were looking for a more compact way of generating the HTML, then maybe the following is helpful?

const html=[...new Array(18)].map(_=>`<span style="--i:${Math.ceil(Math.random()*40+10)};"></span>`).join("\n");
console.log(html); // can be commented out ...
document.querySelector(".particle").innerHTML=html;
<header>
 <a href="#" class="loo">cat <i class="fa-d fa-ct"></i></a>
 <div class="particle"></div>
</header>

Sign up to request clarification or add additional context in comments.

1 Comment

You are the GOAT!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.