Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
Estoy haciendo un Javascript Toggler, así que puse dos imágenes, una de noche y otra de día, la imagen de noche no sale correctamente

Estoy haciendo un Javascript Toggler, así que puse dos imágenes, una de noche y otra de día, la imagen de noche no aparece correctamente, consulte las siguientes capturas de pantalla para esas:

El día viene muy bien

Pero la imagen en la noche no sale correctamente.

Aquí está mi html -

 <!DOCTYPE html> <html> <head> <style> #upperpart h1{ margin-top:12%; } </style> <meta charset="utf-8"> <meta name="viewport" content="width=devicxe-width"> <title>JavaScript</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body id = "body"> <div id = "upperpart"> <center> <h1>JavaScriptToggler</h1> <button onclick = "tagmahalday()">Day</button> <button onclick = "tagmahalnight()">Night</button> <center> </div> <center> <img src = "thumbnail.png" id = "thumb"></center> <script src="script.js"></script> </body> </html>

Aquí está mi CSS -

 button{ border-radius:200px; background-color:antiquewhite; padding:15px; padding-left:60px; padding-right:60px; text-align:center; color:Black; font-size:17.5px; margin:5px; }

Aquí está mi J -

 function tagmahalday(){ document.getElementById("body").style.backgroundImage = "url(backgrounds/tjmahalday.jpg)" } function tagmahalnight(){ document.getElementById("body").style.backgroundImage = "url(backgrounds/tjmahalnight.jpg)" }

Aquí están las imágenes a las que me referí:

Taj Mahal de día - https://cdn.britannica.com/86/170586-050-AB7FEFAE/Taj-Mahal-Agra-India.jpg

Taj Mahal de noche - https://www.holidify.com/blog/wp-content/uploads/2015/02/album_pic20.jpg

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Esto se debe a que no está configurando la propiedad de tamaño de fondo. Este código debería resolver tu problema:

 #body { background-size: cover; // or 100% }
about 4 years ago · Juan Pablo Isaza Denunciar

0

La imagen se repite porque es demasiado pequeña. Deberías encontrar una mejor imagen para la noche. Puede detener la repetición y estirar la imagen de esta manera:

 body { background-size: 100%; background-repeat: no-repeat; }

Pero todavía no se verá bien.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Agregue algo de CSS, esto solucionará su problema

 #body{ background-position: center; background-repeat: no-repeat; background-size: cover; width: 100%; height: 100vh;

}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda