Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!