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

486
Vistas
Buttons with different size images from sprite as background, images not placed correctly

I create some buttons, with images from a sprite to be used as the background for them. Each button is contained within its own <figure>. When the button is selected, the full size image from the Sprite should be displayed. The full size images are displayed correctly, but the thumbnail images on the buttons aren’t in the right positions.

Part of the Blue thumbnail appears with the Red shape thumbnail.
The rest of the Blue shape thumbnail appears where the full blue thumbnail should be, and the Green thumbnail is tacked onto it.
Nothing appears where the Green shape thumbnail should be.

This is what is displayed. enter image description here

Here’s the relevant part of my code. What am I doing wrong?

The CSS

#img1, #img2, #img3,
#thumb1, #thumb2, #thumb3 {
  background: url("colours-full.jpeg");
  background-repeat: no-repeat;
  object-fit: none;
}

#thumb1, #thumb2, #thumb3 {
  width: 30em;
  height: 30em;
  background-size: cover;
  float: left;
  margin-right: 1.5em;
}

#img1 {object-position: 0 0;
  width:  422px;
  height: 287px;
}
#thumb1 { background-position: 0 0; }

#img2 {object-position: -422px 0;
  width:  374px;
  height: 374px;
}
#thumb2 { background-position: -30em 0; }

#img3 {object-position: -796px 0;
  width:  151px;
  height: 560px;
}
#thumb3 { background-position: -60em 0; }

The button creation

function imgBtn (figNum) {
//  Insert a button with thumbnail image
    let html = '<button type="button" ' +
                       'id="thumb' + figNum +
                     '" onclick="showBigImg (' + figNum + ')"></button>';

    const figcap = document.getElementById("fig" + figNum).firstElementChild;
    figcap.insertAdjacentHTML ("afterend", html);  /* Append the button to 
                                                      the figcaption */
}
about 4 years ago · Juan Pablo Isaza
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