Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

304
Visualizações
background-image is not working when using url() method?

im trying to put image in the background by using background-img:url(imageLing) but not working and it's return to me when inspect the element background-image: url(assets/backgrounds/5.jpg); what is the issue : this is my code

//login page 

<LoginWrapper img={`assets/backgrounds/${randomImage}.jpg`}>
        <Wrapper>
          <LoginForm onClickLogin={login} />
        </Wrapper>
      </LoginWrapper>

//css file using styled- components 

interface LoginProps {
  img: string;
}

export const LoginWrapper = styled.div<LoginProps>`
  display: flex;
  align-items: center;
  justify-content: center;
  height: 93vh;
  background-image: url(${({ img }) => img});
  background-size: cover;
  background-repeat: no-repeat;
`;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

React generally bundles your project before deployment which minifies images and changes image path. Hence, passing the path via props will not work. In order to get images to load properly, you have to reference them dynamically as an import.

Login Page

//login page 
import img from './assets/backgrounds/bg.gif'; // <= update this path according to your folder structure, i've added this path as an example

<LoginWrapper img={img}>
    <Wrapper>
      <LoginForm onClickLogin={login} />
    </Wrapper>
</LoginWrapper>

CSS File Option 1 (using img from props)

//css file using styled- components 

// interface LoginProps {
// img: string;
// }

export const LoginWrapper = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
  height: 93vh;
  background-image: url(${({ img }) => img});
  background-size: cover;
  background-repeat: no-repeat;
`;

CSS File Option 2 (importing image in this file itself)

//css file using styled- components 

import img from './assets/backgrounds/bg.gif'; // <= update this path according to your folder structure, i've added this path as an example

export const LoginWrapper = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
  height: 93vh;
  background-image: url(${img});
  background-size: cover;
  background-repeat: no-repeat;
`;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda