7

HTML

<div class='wrapper'>
    <div class='elementContainer'>
        This line should start halfway down the yellow box
    </div>
</div>

CSS

.wrapper
{
    position: relative;

    height: 300px;
    width: 400px;

    background: lightyellow;
    border: 1px solid black;
}

.elementContainer
{
    position: relative;
    height: 200px;
    width: 300px;

    padding-top: 50%;

    background: red;
}

Fiddle example: http://jsfiddle.net/jakelauer/s2ZXV/

In the example above, .elementContainer has a padding-top of 50%. This should be calculated based on the parent element's (.wrapper) height, which means it should come out to 150px. Instead, it comes out to 200px. What's going on?

Jake
  • 3,282
  • 8
  • 32
  • 48

1 Answers1

11

The specifications explain why.

<percentage>
The percentage is calculated with respect to the width of the generated box's containing block

50% of 400 is 200.

Explosion Pills
  • 176,581
  • 46
  • 285
  • 363