1
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Flexbox: Alineación y Gap</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #f8fafc;
margin: 0;
padding: 25px;
color: #0f172a;
}
/* Contenedor flexible con altura fija */
.caja-escenario {
display: flex;
justify-content: space-between;
align-items: center;
gap: 16px;
background-color: #f1f5f9;
border: 2px dashed #94a3b8;
border-radius: 12px;
padding: 20px;
height: 180px;
margin-bottom: 20px;
transition: all 0.3s ease;
}
.elemento {
background: linear-gradient(135deg, #10b981, #059669);
color: white;
padding: 16px 20px;
border-radius: 8px;
font-weight: bold;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
text-align: center;
}
.btn-opcion {
background: #0284c7;
color: white;
border: none;
padding: 8px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 0.85rem;
margin-right: 6px;
margin-bottom: 6px;
}
</style>
</head>
<body>
<h3>Alineación Flexible (justify-content & align-items)</h3>
<div id="escenarioFlex" class="caja-escenario">
<div class="elemento" style="height: 40px; line-height: 40px; padding: 0 20px;">Caja A</div>
<div class="elemento" style="height: 70px; line-height: 70px; padding: 0 20px;">Caja B</div>
<div class="elemento" style="height: 50px; line-height: 50px; padding: 0 20px;">Caja C</div>
</div>
<div>
<strong>Eje Principal (justify-content):</strong><br>
<button class="btn-opcion" onclick="setJustify('center')">center</button>
<button class="btn-opcion" onclick="setJustify('space-between')">space-between</button>
<button class="btn-opcion" onclick="setJustify('space-around')">space-around</button>
<button class="btn-opcion" onclick="setJustify('space-evenly')">space-evenly</button>
<br><br>
<strong>Eje Secundario (align-items):</strong><br>
<button class="btn-opcion" style="background:#475569;" onclick="setAlign('center')">center</button>
<button class="btn-opcion" style="background:#475569;" onclick="setAlign('flex-start')">flex-start</button>
<button class="btn-opcion" style="background:#475569;" onclick="setAlign('flex-end')">flex-end</button>
<button class="btn-opcion" style="background:#475569;" onclick="setAlign('stretch')">stretch</button>
</div>
<script>
const escenario = document.getElementById('escenarioFlex');
function setJustify(val) { escenario.style.justifyContent = val; }
function setAlign(val) { escenario.style.alignItems = val; }
</script>
</body>
</html>
Haz clic para editar este código