Listo (Ctrl + Enter para ejecutar) Bootcamp Fullstack »
index.html
Tab = 4 espacios
1
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <title>Flexbox: Contenedor y Ejes</title>
  <style>
    body {
      font-family: Arial, Helvetica, sans-serif;
      background-color: #f8fafc;
      margin: 0;
      padding: 25px;
      color: #0f172a;
    }

    /* Contenedor flexible */
    .caja-padre {
      display: flex;
      flex-direction: row;
      flex-wrap: nowrap;
      gap: 12px;
      background-color: #e2e8f0;
      padding: 16px;
      border-radius: 12px;
      min-height: 120px;
      transition: all 0.3s ease;
      margin-bottom: 20px;
    }

    /* Elementos hijos flexibles (Flex Items) */
    .item-flex {
      background: linear-gradient(135deg, #0284c7, #2563eb);
      color: white;
      padding: 16px 20px;
      border-radius: 8px;
      font-weight: bold;
      text-align: center;
      min-width: 90px;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .btn-control {
      background: #0f172a;
      color: white;
      border: none;
      padding: 8px 14px;
      border-radius: 6px;
      cursor: pointer;
      font-size: 0.85rem;
      font-weight: 600;
      margin-right: 6px;
      margin-bottom: 6px;
    }
  </style>
</head>
<body>

  <h3>Contenedor Flexible (display: flex)</h3>
  <div id="contenedorFlex" class="caja-padre">
    <div class="item-flex">1. HTML5</div>
    <div class="item-flex">2. CSS3</div>
    <div class="item-flex">3. JavaScript</div>
    <div class="item-flex">4. PHP 8.3</div>
    <div class="item-flex">5. MySQL</div>
  </div>

  <div>
    <strong>Cambiar Dirección:</strong><br>
    <button class="btn-control" onclick="setDirection('row')">Fila (row)</button>
    <button class="btn-control" onclick="setDirection('column')">Columna (column)</button>
    <button class="btn-control" onclick="setDirection('row-reverse')">Fila Invertida (row-reverse)</button>
    <button class="btn-control" style="background:#2563eb;" onclick="toggleWrap()">Alternar Wrap (Salto de línea)</button>
  </div>

  <script>
    const box = document.getElementById('contenedorFlex');
    function setDirection(dir) {
      box.style.flexDirection = dir;
    }
    function toggleWrap() {
      box.style.flexWrap = (box.style.flexWrap === 'wrap') ? 'nowrap' : 'wrap';
    }
  </script>

</body>
</html>
Haz clic para editar este código
Vista Previa
Motor de Render CSS3