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

174
Vistas
Positioning an absolute element above other elements

So I am building this frontendmentor site and im having trouble positioning the shopping cart div on top of the rest of the elements. At first i tried using z-index but apparently that doesnt work with elements that have a position style. I used position relative on the parent and absolute on the child so it would always appear under the shopping cart icon. Is there any other way to force an element on top or should i change the way i position the div.

.right-container {
  padding: 1rem;
}

.account-container {
  display: flex;
  align-items: center;
  position: relative;
}

.cart-icon-container {
  margin-right: 2rem;
}

.cart-icon-container img {
  height: 30px;
  width: 30px;
  aspect-ratio: 1;
}

.shopping-cart-overlay {
  position: absolute;
  top: 5rem;
  right: 100px;
  width: 400px;
  border-radius: 10px;
  box-shadow: 0 1rem 10px rgba(0, 0, 0, 0.185);
}

.shopping-cart-content {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem 1rem;
}
<div class="right-container">
  <div class="account-container">
    <div class="shopping-cart-overlay">
      <div class="shopping-cart-header">
        <h4>Cart</h4>
      </div>
      <div class="shopping-cart-content">
        <p>Your cart is empty</p>
      </div>
    </div>
    <a href="/index.html" class="cart-icon-container">
      <img src="./images/icon-cart.svg" alt="cart">
    </a>
    <img class="avatar" src="./images/image-avatar.png" alt="profile-pic">
  </div>
</div>

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

0

Well it does work. Read this to get a better understanding of how z-index works with position. You just couldn't notice it because the div was transparent.

Check out the snippet below. It's your exact code, but I changed the background and positioned the .shopping-cart-overlay element closer to the other elements, just to show you that it actually works.

.right-container {
  padding: 1rem;
}

.account-container {
  display: flex;
  align-items: center;
  position: relative;
}

.cart-icon-container {
  margin-right: 2rem;
}

.cart-icon-container img {
  height: 30px;
  width: 30px;
  aspect-ratio: 1;
}

.shopping-cart-overlay {
  position: absolute;
  //top: 5rem;
  //right: 100px;
  width: 400px;
  border-radius: 10px;
  box-shadow: 0 1rem 10px rgba(0, 0, 0, 0.185);
  
  /* Changes */
  top: 0;
  left: 125px;
  z-index: 99;
  background-color: red;
}

.shopping-cart-content {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem 1rem;
}
<div class="right-container">
    <div class="account-container">
      <div class="shopping-cart-overlay">
        <div class="shopping-cart-header">
          <h4>Cart</h4>
        </div>
        <div class="shopping-cart-content">
          <p>Your cart is empty</p>
        </div>
      </div>
      <a href="/index.html" class="cart-icon-container">
        <img src="./images/icon-cart.svg" alt="cart">
      </a>
      <img class="avatar" src="./images/image-avatar.png" alt="profile-pic">
    </div>
  </div>

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