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

235
Visualizações
How to make an icon overlay an Image such that the icon remains in its place when the image is uploaded via javascript?

I'm trying to create an app that has a feature that allows its users to upload images from their computer and that chosen image is displayed as preview. The problem I'm running into is that before the image is selected, an icon button is overlaid on the bottom-right of the image element and when the image is chosen the icon button is pushed off the image element. I want the icon button to stay in its place.

Here's the code pertaining to this part:

<div id="main-container">
     <section id="customer_archetype" style="width: 500px; margin: auto">
         <form method="post" action="./submit_form_data.php" style="display: flex; flex-direction: column;">
           <div style="margin: auto;">
              <div style="width: 150px; height: 150px; background-color: #E1E0E1; border-radius: 100px; ">
                   <img id= "uploaded_image" src="#" style="display:none; width: 150px; height: 150px; border-radius: 100px;" >
                   <input style="display:none" name = "archetype_image_input" id="archetype_image_input" type="file" accept="image/*">
                   <img src="./images/camera.png" id="cam_img" style="width:22px; height:22px; color:gray; z-index = 1; cursor: pointer ; margin-left:105px; margin-top: 125px;">
               </div>
              </div>    
              <div id = "input_fields" style="display: flex; flex-direction: column; margin: 10px auto; width: 400px;">
           </div>
         </form>
         <div style="text-align: center;">
             <button style="width: 100px" id="add-input-field-btn">Add Field</button>
             <button id="remove-input-field-btn">Remove Field</button>
         </div>
     </section>
</div>

The code that I have written for the image and icon button

And here's the look of the output before the image is chosen:

Picture of output before image is chosen

Output after image is chosen. As you can see the icon is pushed off:

Output after image is chosen

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to set the image container as position: relative and then with the icon (the camera image), set it to be position: absolute.

Don't use margin properties to place an image like this, it's subject to move as the DOM is changed.

Here's a working example using your code. I've added classes to make viewing the styling easier.

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