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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…