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

114
Vistas
Can't get a buttons background image to display

Tried searching for an answer on this but didn't find anything that worked.

Im working in React, using styled-components.

Got a styles.js file that contains all my css for a component I'm working on. Problem is, I'm trying to put an image of a dice on a set of buttons. The buttons are used in the component as:

<Button></Button>

If I want to overwrite a particular buttons style, I have rules (as props I think?) in the same styles.js file. Here's what this specific problem button is:

// Style override for a Randomiser Button
${props => props.RANDButton && css`
background: transparent url('../Images/D20.png') no-repeat;

width: 50px;
height: 50px;

border: outset 1px;
border-radius: 0px;
`}

Here's the 'original' code that all buttons use unless overwritten:

//style(s) for a button
export const Button = styled.button`
  background-color: rgb(100,250,100);
  box-shadow: 2px 2px 3px black;
  color: black;

  border: outset;
  border-radius: 10px;
  
  padding: 5px;
  margin: 5px;
  text-align: Center;
  width: auto;
  
  font-weight: bolder;
  font-size: 1.5rem;
  font-variant: small-caps;
...
*Other css rules*
...
`;

Then, this specific button is used like so:

<Button RANDButton></Button>

Sorry, I can't recall the proper terminology for this method.

When I save, and the component re-renders, it doens't show the image

Screenshot of Component not displaying button image

If I've missed something basic, please could someone point it out to me?

Thanks

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

0

it's duplicate question , you can find the right answer in below link React.js styled-components importing images and using them as div background

about 4 years ago · Juan Pablo Isaza Denunciar

0

Issue was that images, unless explicity imported as:

import D20 from './Images/D20.png';

and then used as:

  background: url(${D20});

...will be minified and have their URL changed thanks to webpack.

Found answer here:

https://stackoverflow.com/a/56404570/2796017

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