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

110
Visualizações
Overlay one image into another with z-index

I am trying to overlay one image into another but it not working.

My code

body {
  background: #000000 50% 50%;
  height: 100%
  width:100%;
  overflow-x: hidden;
  overflow-y: hidden;
}

.neer {
  z-index: 100;
  position: absolute;
}

.mobile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 30px;
}
<div class="mobile">
  <p style="color: blue; font-size: 40px;">Overlay image</p>
  <div class="neer">
    <img src="https://growtraffic-bc85.kxcdn.com/blog/wp-content/uploads/2019/02/336-x-280.jpg" />

  </div>
  <div>
    <img src="https://place-hold.it/338x280" />
  </div>
</div>

I am not using margin-top or margin-bottom because i am looking in responsive. defining margin sometime break the layout in different structure.

almost 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

there are many ways to do that. a simple way using your giving code is to remove flex style from mobile and put it in body.

* {
  /* border: 1px solid red; */
}

body {
  background: #000000 50% 50%;
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.neer {
  z-index: 100;
  position: absolute;
}

.mobile {
  /* display: flex; */
  /* flex-direction: column; */
  /* align-items: center; */
  /* justify-content: center; */
  height: 100%;
  gap: 30px;
}
<div class="mobile">
  <p style="color: blue; font-size: 40px;">Overlay image</p>

  <div class="neer">
    <img src="https://growtraffic-bc85.kxcdn.com/blog/wp-content/uploads/2019/02/336-x-280.jpg" />
  </div>

  <div class="behind">
    <img src="https://place-hold.it/338x280" />
  </div>
</div>

a better way is to put both pictures in one div then give them the same position in that div.

* {
  /* border: 1px solid red; */
}

body {
  background: #000000 50% 50%;
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.container {
  display: flex;
  align-items: center;
  justify-content: center;
}

.neer {
  z-index: 100;
  position: absolute;
}

.mobile {
  /* display: flex; */
  /* flex-direction: column; */
  /* align-items: center; */
  /* justify-content: center; */
  height: 100%;
  gap: 30px;
}
<div class="mobile">
  <p style="color: blue; font-size: 40px;">Overlay image</p>

  <div class="container">

    <div class="neer">
      <img src="https://growtraffic-bc85.kxcdn.com/blog/wp-content/uploads/2019/02/336-x-280.jpg" />
    </div>

    <div class="behind">
      <img src="https://place-hold.it/338x280" />
    </div>
  </div>

</div>

If we know why you want to do this, there might be a better way.

almost 4 years ago · Santiago Trujillo Relatório

0

Place both images inside a div with position: relative;. Add this class to the image that should be on top:

.neer {
  z-index: 100;
  position: absolute;
  top: 0;
  left: 0;
}

body {
  background: #000000 50% 50%;
  height: 100%
  width:100%;
  overflow-x: hidden;
  overflow-y: hidden;
}

.neer {
  z-index: 100;
  position: absolute;
  top: 0;
  left: 0;
}

.mobile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 30px;
}
<div class="mobile">
  <p style="color: blue; font-size: 40px;">Overlay image</p>
  
  <div style="position: relative;">
    <img src="https://place-hold.it/338x280" />   
    <img class="neer" src="https://growtraffic-bc85.kxcdn.com/blog/wp-content/uploads/2019/02/336-x-280.jpg" />
  </div>
</div>

almost 4 years ago · Santiago Trujillo 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