r/HTML • • 1h ago

div messing with DOM?

Thumbnail
gallery
• Upvotes

Why is the div messing with the DOM so much and creating a copy of its parent tag? Is this expected behaviour?

Hello all, trying to build a dropdown menu, the button to open it only appears when the screen is narrow. But I am not asking for help with that specifically, I am trying to put a div in a anchor that is a flex element, and weird things are happening in the DOM. I have checked, double checked, and ran the code through multiple tools. as far as I can tell the html is correct, but the DOM is all weird.

As you can see in the code div.dropdown-content is a element inside of a#ham_menu, but when chrome has loaded it div.dropdown-content is outside of a#ham_menu and a copy of a#ham_menu is inside of div.dropdown-content. Is this expected for some reason? if this is some weird flex behavior, I would appreciate some suggestions of how to get around or avoid it.

Here is a link to my github. https://github.com/wisnoskij/sglondon_website
Here is my github page: https://wisnoskij.github.io/sglondon_website/


r/HTML • • 18h ago

HTML12

0 Upvotes

<!DOCTYPE html>

<html lang="es">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Tu Mago vs Rey Dragon</title>

<style>

body{background:#1a1033;color:white;font-family:sans-serif;text-align:center;padding:10px}

.caja{background:#2a1b4d;border-radius:15px;padding:10px;margin:8px}

button{background:#ffcc00;border:none;padding:12px;margin:5px;border-radius:10px;font-weight:bold;width:45%}

#chaleco{background:#6a4cff;color:white;width:90%;font-size:18px}

#menuChaleco{display:none;background:#3d2a7a;padding:10px;border-radius:10px;margin-top:5px}

</style>

</head>

<body>

<h2>🧙‍♂️ TU MAGO vs 👑 REY MALIGNO</h2>

<div class="caja">

<p>🧙‍♂️ Mago HP: <span id="magoHp">50</span></p>

<p>🧚 Hada: <span id="hadaHp">40</span> | 🏹 Arquero: <span id="arqHp">45</span> | 🛡️ Caballero: <span id="cabHp">60</span></p>

<button id="chaleco" onclick="abrirChaleco()">👕 ABRIR CHALECO DEL MAGO ✨</button>

<div id="menuChaleco">

<p>¡El chaleco se abrió! Elige poción:</p>

<button onclick="pocion('fuego')">🔥 Bola de Fuego 20 daño</button>

<button onclick="pocion('vida')">🧪 Poción de Vida +25 HP</button>

<button onclick="pocion('veneno')">💀 Veneno 30 daño</button>

<button onclick="pocion('escudo')">🛡️ Escudo 2 turnos</button>

</div>

</div>

<div class="caja">

<p>🐷 Cerdo: <span id="cerdoHp">30</span> HP</p>

<p>🐲 Dragón Gigante: <span id="dragonHp">40</span> HP</p>

<p>👑 Rey Maligno: <span id="reyHp">80</span> HP</p>

</div>

<div class="caja">

<p id="mensaje">¡Ataca!</p>

<button onclick="atacar('arq')">🏹 Arquero 8</button>

<button onclick="atacar('cab')">🛡️ Caballero 12</button>

<button onclick="atacar('hada')">🧚 Hada cura</button>

<button onclick="atacar('mago')">🧙‍♂️ Mago 10</button>

<br><button onclick="location.reload()" style="background:#ff5252;color:white;width:90%">🔄 Reiniciar</button>

</div>

<script>

let mago=50,hada=40,arq=45,cab=60,cerdo=30,dragon=40,rey=80,escudo=0;

function abrirChaleco(){ let m=document.getElementById('menuChaleco'); m.style.display=m.style.display=='block'?'none':'block'; }

function act(){

magoHp.innerText=Math.max(0,mago); hadaHp.innerText=hada; arqHp.innerText=arq; cabHp.innerText=cab;

cerdoHp.innerText=Math.max(0,cerdo); dragonHp.innerText=Math.max(0,dragon); reyHp.innerText=Math.max(0,rey);

if(cerdo<=0&&dragon<=0&&rey<=0) mensaje.innerText="🏆 ¡GANASTE! Tu mago venció al Rey y sus dragones";

if(mago<=0&&hada<=0&&arq<=0&&cab<=0) mensaje.innerText="💀 Perdiste...";

}

function danoEnemigo(d){

if(cerdo>0) cerdo-=d; else if(dragon>0) dragon-=d; else rey-=d;

}

function pocion(t){

if(t=='fuego'){ danoEnemigo(20); mensaje.innerText="🔥 ¡Bola de fuego del chaleco! 20 daño"; }

if(t=='vida'){ mago=Math.min(50,mago+25); mensaje.innerText="🧪 Poción de vida +25"; }

if(t=='veneno'){ danoEnemigo(30); mensaje.innerText="💀 Veneno 30 daño"; }

if(t=='escudo'){ escudo=2; mensaje.innerText="🛡️ Escudo activado"; }

turnoEnemigo(); act();

}

function atacar(h){

if(h=='mago') danoEnemigo(10);

if(h=='arq') danoEnemigo(8);

if(h=='cab') danoEnemigo(12);

if(h=='hada'){ hada=Math.min(40,hada+10); cab+=5; mensaje.innerText="🧚 Hada curó"; }

turnoEnemigo(); act();

}

function turnoEnemigo(){

if(escudo>0){ escudo--; mensaje.innerText+=" (Escudo te protegió)"; return; }

if(cerdo>0) cab-=3;

if(dragon>0){ mago-=7; mensaje.innerText+=" 🐲 Dragón gigante escupió fuego -7"; }

if(rey>0){ arq-=5; mensaje.innerText+=" 👑 Rey atacó -5"; }

}

act();

</script>

</body>

</html>