lunes, 23 de marzo de 2020

Diseño responsivo con CSS

La estructura básica de una página web con HTML5 es:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Título de la página</title>
  5. <!-- METATAGS, archivos externos, etc. -->
  6. </head>
  7. <body>
  8. Contenido de la página
  9. </body>
  10. </html>

Para implementar un diseño responsivo debemos agregar un archivo CSS, que llamaremos estructura.css, se ubicará dentro de una carpeta css y su código es:

  1. * {box-sizing: border-box;}
  2. body {
  3. margin: 0;
  4. padding: 0;
  5. width: 100%;
  6. }
  7. .fila {margin: 0 auto;}
  8. .fila::after {
  9. content: "";
  10. clear: both;
  11. display: table;
  12. }
  13. [class*="col-"] {
  14. width: 100%;
  15. float: left;
  16. }
  17. html {font-size: 16px;}
  18. .fila {width: 80%;}
  19. [class*="col-"] {padding: 1rem;}
  20. .col-1 {width: 8.33%;}
  21. .col-2 {width: 16.66%;}
  22. .col-3 {width: 25%;}
  23. .col-4 {width: 33.33%;}
  24. .col-5 {width: 41.66%;}
  25. .col-6 {width: 50%;}
  26. .col-7 {width: 58.33%;}
  27. .col-8 {width: 66.66%;}
  28. .col-9 {width: 75%;}
  29. .col-10 {width: 83.33%;}
  30. .col-11 {width: 91.66%;}
  31. .col-12 {width: 100%;}

El archivo para probar si nuestra página funciona sería el archivo index.html:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Inlearning Code - Responsive</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <!-- Archivo CSS -->
  8. <link href="css/estructura.css" rel="stylesheet" type="text/css" />
  9. </head>
  10. <body>
  11. <header class="fila">
  12. <div class="col-10" style="background-color: #b4e3cc;">COL 10</div>
  13. <div class="col-2" style="background-color: #ff5733;">COL 2</div>
  14. </header>
  15. <div class="fila">
  16. <div class="col-4" style="background-color: #decd3e;">COL 4</div>
  17. <div class="col-4" style="background-color: #a4e57c;">COL 4</div>
  18. <div class="col-4" style="background-color: #dfc80c;">COL 4</div>
  19. </div>
  20. <footer class="fila">
  21. <div class="col-12" style="background-color: #ffa200;">COL 12</div>
  22. </footer>
  23. </body>
  24. </html>

El resultado sería:

No hay comentarios:

Publicar un comentario