-2
I’m improving on html and Javascript while creating my own project. I don’t know if my question is correct, but I’ll be explaining it in the best way.
I’m creating a tool to help combat turns in table RPG, for this I’m using html and css to create cards containing information of characters and monsters, only the code ends up getting huge and with many repeated lines.
Cards are following this pattern:
<!-- Iniciando o card -->
<div class="boards">
<div class="board">
<h3> 1º </h3>
<input placeholder="Nome" class="inpNome">
<div class="dropzone">
<div class="card" draggable="true">
<!-- Informações dentro do card -->
<img src="" alt="" width="260" height="200">
<div class="areaSaude">
<button class="btnDano">Dano</button>
<input type="number" min="0" class="inpValor">
<button class="btnCura">Cura</button>
</div>
<div class="area">
<div class="status">
<div class="status-life"></div>
<div class="grid-barra">
<div class="heartLifeBar">
<img id="heart" src="./view/imagens/heartLifeBar.png" alt="coração" />
</div>
<div class="total">
<input placeholder="0" class="varLife">
<span class="spnBar">/</span>
<input placeholder="0" class="lifeTotal">
</div>
</div>
</div>
</div>
<div class="area">
<div class="status">
<div class="status-shield"></div>
<div class="grid-barra">
<div class="shieldMob">
<img id="EscudoMob" src="./view/imagens/shield.svg" alt="Escudo" />
</div>
<div class="total-shield">
<input placeholder="0" class="varEscudo">
<span class="spnBar">/</span>
<input placeholder="0" class="escudoTotal">
</div>
</div>
</div>
</div>
<div class="containerSentido">
<div class="sentidos">
<img class="sentido1" src="./view/imagens/senses.svg" alt="Sentidos" />
<div class="percepcao">Perception</div>
<div class="numPercepcao">15</div>
<img class="sentido1" src="./view/imagens/senses.svg" alt="Sentidos" />
<div class="percepcao">Investigation</div>
<div class="numPercepcao">12</div>
<img class="sentido1" src="./view/imagens/senses.svg" alt="Sentidos" />
<div class="percepcao">Insight</div>
<div class="numPercepcao">13</div>
</div>
</div>
<!-- Fim do conteúdo -->
</div>
</div>
</div>
</div>
<!-- Fim do card -->
With this I was thinking of a way to save the information of the ready mobs in another file to decrease the size of the code. Type have multiple html files containing information from different mobs, example: minotaur.html
, goblin.html
..., and leave only the empty card in the main code ready to receive information from the monster or character by clicking a button.
Thus:
<!-- Iniciando o card -->
<div class="boards">
<div class="board">
<h3> 6º </h3>
<input placeholder="Nome" class="inpNome">
<div class="dropzone">
<div class="card" draggable="true">
<!-- Informações dentro do card -->
<button onClick="puxar informações">
<!-- Fim do conteúdo -->
</div>
</div>
</div>
</div>
<!-- Fim do card -->
I accept tips on how to improve code, how to solve the problem, links to study.
Apparently you can use the
template
and theslot
: https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_templates_and_slots.– Inkeliz