• Inicio
  • Buscar
  • Ingresar
  • Registrarse

    Seguridad en gadgets tecnológicos: todo lo que necesitas saber para protegerte

    • Hack x Crack - Comunidad de Seguridad informática »
    • Programación »
    • Programación Web »
    • Crear ventana modal con HTML & CSS
    • Imprimir
    Páginas: [1]   Ir Abajo

    Autor Tema: Crear ventana modal con HTML & CSS  (Leído 4895 veces)

    Desconectado R3LI4NT

    • { L4 } Geek
    • ****
    • Mensajes: 379
    • El poder del usuario radica en su ANONIMATO.
      • Ver Perfil
      • GitHub
    Crear ventana modal con HTML & CSS
    « en: Octubre 24, 2021, 03:39:39 am »
    Un ventana modal es una capa que se muestra por encima del contenido visual de una página web generalmente activado por una acción como un click o temporizador. Muestra un contenido con una o varias opciones a elegir por el usuario.

    1-





    HTML:

    Código: Text
    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4.     <meta charset="UTF-8">
    5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7.     <title>Ventana Modal</title>
    8.     <link rel="stylesheet" href="style.css">
    9.     <link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
    10. </head>
    11. <body>
    12.     <div class="container-modal">
    13.         <div class="modal-btn">
    14.             <button><a href="#mostrar-modal">Mostrar Ventana</a></button>
    15.         </div>
    16.     </div>
    17.  
    18.     <div id="mostrar-modal" class="ventana-modal">
    19.         <div>
    20.             <a href="#" class="cerrar"><i class='bx bx-x-circle'></i></a>
    21.             <h1>My name is...</h1>
    22.             <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Neque, fugiat facere soluta itaque voluptates nam! A voluptas repellendus adipisci cupiditate</p>
    23.             <button class="info-btn"><a href="#">Más info</a></button>
    24.         </div>
    25.     </div>
    26. </body>
    27. </html>
    28.  


    CSS:

    Código: CSS
    1. @import url('https://fonts.googleapis.com/css2?family=Sansita:[email protected]&display=swap');
    2. @import url('https://fonts.googleapis.com/css2?family=Poppins:[email protected];400&display=swap');
    3.  
    4. * {
    5.     padding: 0;
    6.     margin: 0;
    7.     box-sizing: border-box;
    8. }
    9.  
    10. body {
    11.     background-color: #fff;
    12.     height: 100vh;
    13.     width: 100%;
    14.     align-items: center;
    15.     justify-content: center;
    16.     display: flex;
    17.     position: relative;
    18. }
    19.  
    20. .container-modal {
    21.     display: flex;
    22.     justify-content: center;
    23.     align-items: center;
    24.     height: 100vh;
    25. }
    26.  
    27. button {
    28.     background: #121212;
    29.     padding: 10px 17px;
    30.     border: 2px solid #00AEF0;
    31.     outline: none;
    32.     border-radius: 12px;
    33.     box-shadow: 0 3px 10px rgba(0,0,0,.6);
    34. }
    35.  
    36. button a {
    37.     text-decoration: none;
    38.     color: #fff;
    39.     font-family: 'Sansita', sans-serif;
    40.     font-size: 17px;
    41.     text-transform: uppercase;
    42.     letter-spacing: 1px;
    43. }
    44.  
    45. .ventana-modal {
    46.     position: fixed;
    47.     top:0;
    48.     right: 0;
    49.     left: 0;
    50.     bottom: 0;
    51.     z-index: 9999;
    52.     visibility: hidden;
    53.     pointer-events: none;
    54.     transition: all 0.4s;
    55. }
    56.  
    57. .ventana-modal:target {
    58.     visibility: visible;
    59.     opacity: 1;
    60.     pointer-events: auto;
    61. }
    62.  
    63. .ventana-modal > div {
    64.     width: 500px;
    65.     height: 250px;
    66.     position: absolute;
    67.     top: 50%;
    68.     left: 50%;
    69.     transform: translate(-50%,-50%);
    70.     padding: 2rem;
    71.     background: #121212;
    72.     color: #f2f2f2;
    73.     border-radius: 2rem;
    74.     box-shadow: 0 3px 10px rgba(0,0,0,.5);
    75. }
    76.  
    77. .ventana-modal h1 {
    78.     font-size: 2em;
    79.     margin: 0 0 15px;
    80.     font-family: 'Poppins', sans-serif;
    81.     font-weight: 400;
    82. }
    83.  
    84. .ventana-modal p {
    85.     font-family: 'Poppins', sans-serif;
    86.     font-weight: 3000;
    87.     font-size: 13px;
    88.     text-align: justify;
    89. }
    90.  
    91. .cerrar {
    92.     color: #ccc;
    93.     line-height: 50px;
    94.     font-size: 80%;
    95.     position: absolute;
    96.     right: 0;
    97.     top: 0;
    98.     width: 70px;
    99.     text-decoration: none;
    100.     font-family: 'Poppins', sans-serif;
    101.     font-weight: 300;
    102.     cursor: pointer;
    103.     transition: 0.2s;
    104. }
    105.  
    106. i {
    107.     font-size: 20px;
    108.     margin-left: 20px;
    109.     margin-top: 20px;
    110. }
    111.  
    112. .cerrar:hover {
    113.     color: #E32525;
    114. }
    115.  
    116. .info-btn {
    117.     margin: 30px 0;
    118.     border-radius: 20px;
    119. }
    120.  
    121. .info-btn a {
    122.     font-size: 12px;
    123.     font-family: 'Poppins', sans-serif;
    124.     font-weight: bold;
    125.     color: #EFEFEF;
    126.     transition: 0.2s;
    127. }
    128.  
    129. .info-btn a:hover {
    130.     color: #00AEF0;
    131. }
    132.  



    2-





    HTML:

    Código: Text
    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4.     <meta charset="UTF-8">
    5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7.     <title>Ventana Modal</title>
    8.     <link rel="stylesheet" href="style.css">
    9.     <link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
    10. </head>
    11. <body>
    12.     <div class="container-modal">
    13.         <div class="modal-btn">
    14.             <button><a href="#mostrar-modal">Mostrar Ventana</a></button>
    15.         </div>
    16.     </div>
    17.  
    18.     <div id="mostrar-modal" class="ventana-modal">
    19.         <div>
    20.             <a href="#" class="cerrar"><i class='bx bx-x'></i></a>
    21.             <i class='bx bx-envelope'></i><h1>Recibe todas las novedades por mail</h1>
    22.             <input type="text" placeholder="Email..." class="email-input">
    23.             <textarea placeholder="Escribe aquí tus comentarios" id="" cols="40" rows="4"></textarea>
    24.             <button class="sub-btn"><a href="#">Suscribirse</a></button>
    25.         </div>
    26.     </div>
    27. </body>
    28. </html>
    29.  


    CSS:

    Código: CSS
    1. @import url('https://fonts.googleapis.com/css2?family=Sansita:[email protected]&display=swap');
    2. @import url('https://fonts.googleapis.com/css2?family=Poppins:[email protected];400&display=swap');
    3.  
    4. * {
    5.     padding: 0;
    6.     margin: 0;
    7.     box-sizing: border-box;
    8. }
    9.  
    10. body {
    11.     background-color: #fff;
    12.     height: 100vh;
    13.     width: 100%;
    14.     align-items: center;
    15.     justify-content: center;
    16.     display: flex;
    17.     position: relative;
    18. }
    19.  
    20. .container-modal {
    21.     display: flex;
    22.     justify-content: center;
    23.     align-items: center;
    24.     height: 100vh;
    25. }
    26.  
    27. .modal-btn button {
    28.     background: #121212;
    29.     padding: 10px 17px;
    30.     border: 2px solid #00AEF0;
    31.     outline: none;
    32.     border-radius: 12px;
    33.     box-shadow: 0 3px 10px rgba(0,0,0,.6);
    34. }
    35.  
    36. button a {
    37.     text-decoration: none;
    38.     color: #fff;
    39.     font-family: 'Sansita', sans-serif;
    40.     font-size: 17px;
    41.     text-transform: uppercase;
    42.     letter-spacing: 1px;
    43. }
    44.  
    45. .ventana-modal {
    46.     position: fixed;
    47.     top:0;
    48.     right: 0;
    49.     left: 0;
    50.     bottom: 0;
    51.     z-index: 9999;
    52.     visibility: hidden;
    53.     pointer-events: none;
    54.     transition: all 0.4s;
    55. }
    56.  
    57. .ventana-modal:target {
    58.     visibility: visible;
    59.     opacity: 1;
    60.     pointer-events: auto;
    61. }
    62.  
    63. .ventana-modal > div {
    64.     width: 500px;
    65.     height: 350px;
    66.     position: absolute;
    67.     top: 50%;
    68.     left: 50%;
    69.     transform: translate(-50%,-50%);
    70.     padding: 10px;
    71.     background: #0984e3;
    72.     color: #f2f2f2;
    73.     border-radius: 8px;
    74.     border: 3px solid rgba(54,54,54);
    75.     box-shadow: 0 3px 10px rgba(0,0,0,.5);
    76. }
    77.  
    78. .ventana-modal h1 {
    79.     font-size: 1.6rem;
    80.     margin: 15px 60px;
    81.     font-family: 'Poppins', sans-serif;
    82.     font-weight: 400;
    83.     padding: 0 10px;
    84.     color: #f2f2f2;
    85. }
    86.  
    87. .bx-envelope {
    88.     font-size: 40px;
    89.     position: absolute;
    90.     color: #fff;
    91.     margin-left: 10px;
    92.     top: 20px;
    93. }
    94.  
    95. .cerrar {
    96.     color: #ccc;
    97.     line-height: 50px;
    98.     font-size: 80%;
    99.     position: absolute;
    100.     right: 0;
    101.     top: 0;
    102.     width: 70px;
    103.     text-decoration: none;
    104.     font-family: 'Poppins', sans-serif;
    105.     font-weight: 300;
    106.     cursor: pointer;
    107.     transition: 0.2s;
    108. }
    109.  
    110. .bx-x {
    111.     left: 30px;
    112.     bottom: -15px;
    113.     position: absolute;
    114.     font-size: 40px;
    115.     margin-left: 20px;
    116.     margin-top: 20px;
    117.     background: #D74C6B;
    118.     border-radius: 50%;
    119.     color: #fff;
    120.     border: 2px solid rgba(54,54,54);
    121. }
    122.  
    123. .email-input {
    124.     position: relative;
    125.     top: 20px;
    126.     width: 80%;
    127.     display: flex;
    128.     justify-content: center;
    129.     align-items: center;
    130.     margin: 0 45px;
    131.     outline: none;
    132.     height: 30px;
    133.     padding: 0 6px;
    134.     font-family: 'Poppins', sans-serif;
    135.     border: 1px solid rgba(0,0,0,.8);
    136. }
    137.  
    138. textarea {
    139.     position: relative;
    140.     top: 30px;
    141.     width: 80%;
    142.     display: flex;
    143.     justify-content: center;
    144.     align-items: center;
    145.     margin: 0 45px;
    146.     outline: none;
    147.     padding: 0 6px;
    148.     font-family: 'Poppins', sans-serif;
    149.     border: 1px solid rgba(0,0,0,.8);
    150. }
    151.  
    152.  
    153. .sub-btn {
    154.     margin: 60px 163px;
    155.     border-radius: none;
    156.     background: #0668B3;
    157.     border: 2px solid rgba(0,0,0,.8);
    158.     padding: 10px 20px;
    159. }
    160.  
    161. .sub-btn a {
    162.     font-size: 15px;
    163.     font-family: 'Poppins', sans-serif;
    164.     font-weight: bold;
    165.     color: #EFEFEF;
    166.     transition: 0.2s;
    167. }
    168.  



    #R3LI4NT
    En línea

    No contesto dudas por MP, si las tienes, las planteas en el foro.

    Road To Hacking v3: https://github.com/R3LI4NT/road-to-hacking

    Desconectado Arcano666

    • { L0 } Ñuub
    • Mensajes: 1
      • Ver Perfil
    Re:Crear ventana modal con HTML & CSS
    « Respuesta #1 en: Enero 13, 2022, 03:45:52 pm »
    Muchas gracias, me ha resultado muy útil para mi web personal
    En línea

    Desconectado Miguelzangorano

    • { L0 } Ñuub
    • Mensajes: 4
      • Ver Perfil
    Re:Crear ventana modal con HTML & CSS
    « Respuesta #2 en: Enero 21, 2022, 09:15:55 pm »
    Está genial una ventana así tipo pop up, hace un tiempo para esta web va sobre frases... sobre amor y cosas así: https://frasesbonitas.wiki/frases-amor/ hice uno igual, y me llevó super poquito tiempo, así nos ahorramos de plugins y tener que cargar mucho más una web.
    En línea

    Desconectado Miguelzangorano

    • { L0 } Ñuub
    • Mensajes: 4
      • Ver Perfil
    Re:Crear ventana modal con HTML & CSS
    « Respuesta #3 en: Enero 21, 2022, 09:16:48 pm »
    Hace un tiempo creo que lo quitaron aun así intentaré verlo... era de color azul y negro.
    En línea

    • Imprimir
    Páginas: [1]   Ir Arriba
    • Hack x Crack - Comunidad de Seguridad informática »
    • Programación »
    • Programación Web »
    • Crear ventana modal con HTML & CSS
     

    • SMF | SMF © 2013, Simple Machines
    • XHTML
    • RSS
    • WAP2
    Va un mudo y le dice a un sordo: Hack x Crack usa cookies. Pues eso... Learn more