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

240
Visualizações
Absolute positioned element height exceeds parent on mobile

I have an element with a background image that contains an absolute positioned element at the bottom.

When the screen width gets narrower, the absolutely positioned element height gets increased and exceeds the parent element. As known that position absolute elements get out of the flow, so the parent height is not changed.

$(window).ready(function() {
  if ($(window).width() <= 767) {
    var heig = $('.overlay').height(),
      parent = $('.parent');
    parent.css('height', heig + 300 + 'px');
  }
});
html,
body {
  margin: 0;
  height: 100%;
}

* {
  box-sizing: border-box;
}

.parent {
  position: relative;
  min-height: 100vh;
  background-image: url(http://placehold.it/1000);
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.overlay {
  background: #376c8d;
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  padding: 30px 20px;
  border-radius: 160px 160px 0 0;
  font-size: 24px;
  opacity: 0.8;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="parent">
  <div class="overlay">
    <img src="http://placehold.it/100" />
    <p>Lorem ipsum dolor sit amet</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing eli</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    <a href="/">Link</a>
    <p>Lorem ipsum dolor sit amet</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing eli</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    <a href="/">Link</a>
  </div>
</div>

Is there is a way to keep the .overlay at the bottom, but all content is shown? Is there is a similar solution with CSS?

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

0

Constrain the proportion by making one property or another relative to the other.

background-size: 100% auto;

Edit:

Use responsive SVG as the .overlay to avoid layout reflow. Or output the content as an image if that suits your workflow or comfort level.

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