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

162
Vistas
How can I overlay a background image in a react component?

I've got an image inside a component and I want to overlay a 0.6 white background on top of it.

import background from "../images/pageBG2.png"; //import an image for bg use

var collectionWindowStyle = {
div:{
    
    
    backgroundImage: `url(${background})`,
    backgroundPosition: 'center',
    backgroundSize: 'cover',
    
    background: 'rgba(255,255,255,0.5)',

    color: "white",
    margin: "5px",
    padding: "5px",
}
,
h1:{
    color: "grey"
},

}

So my thoughts were that if I used "background" after my image, that would overlay pure white on it, but the alpha would allow the image to appear somewhat washed out. All that happens in my react app is that the image is entirely white. What can I do?

And then call this in the component itself

const Bookcollection  = () => {

    return(
        <div style={collectionWindowStyle.div}>
        ...

Tried googling it but didn't find anything by myself.

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

0

Set the component’s position to relative and place a div inside. Then give that child div a position of absolute and inset 0. Then give that same div a white transparent background.

about 4 years ago · Juan Pablo Isaza Denunciar

0

By writing this you are overwriting the image and replacing it with white background

 backgroundImage: `url(${background})`,
    backgroundPosition: 'center',
    backgroundSize: 'cover',
    
    background: 'rgba(255,255,255,0.5)',

You can create a overlay by this :

div:{
    backgroundImage: `url(${background})`,
    backgroundPosition: 'center',
    backgroundSize: 'cover',  
    color: "white",
    margin: "5px",
    padding: "5px",
     '&::before': {
      content: "",
      position: "absolute",
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
      background: "rgba(255,255,255,.5)",
    }
}

The css looks like this :

div:{
....
}

div:before {
  content: "";
  position: absolute;
  left: 0; 
  right: 0;
  top: 0; 
  bottom: 0;
  background: rgba(255,255,255,.5);
}
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