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

134
Visualizações
Child Width Calculation standard?

My question is so simple but rather problematic for me, if a parent div have padding and child's div width is 100%, child's div width is always shorter than its parent one. if i change child div as absolute div and parent div as relative, child's width is just equal to the parent's no matter padding and margin in parents. Like this:

.first {
  background-color: yellow;
  width: 100px;
  height: 100px;
  padding: 10%;
  position: relative;
}

.second {
  background-color: blue;
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 40%;
}
<div class="first">HI
  <div class="second">
    HELLO
  </div>
</div>

Eventhough parent's position is totally relative, so you assume Child is totally dependent on '.first'div. So, I am assuming how is child width is calculated in this case?

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

0

When you set child div to position absolute (and parent has position relative value), then this element is removed from the normal document flow. Also, if left property is set other than 'auto' it is normal to "ignore" the padding because according to W3C docs "These properties specify offsets with respect to the box's containing block" (if it's auto then it shouldn't ignore padding, but width: 100% will "ignore" padding and when parent has 100px then child also will have 100% width.). See also this for answer what is a containing block - https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block.

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