Here is an example:
http://jsfiddle.net/QZAd8/1/
Notice how all of the red divs are the same height
and have padding-top:100%;
, yet they A & B have different padding sizes... and it appears that the width of the parent changes this value (note that C changes the height
of the parent, yet that doesn't alter the padding).
Why is padding related to width in this way?
Edit: for historical reasons, and in case jsfiddle goes away, the code I used in my example is as follows...
.outer {
background-color: green;
height: 300px;
width: 70px;
float: left;
margin-right: 10px;
}
.middle {
background-color: red;
height: 100px;
width: 50px;
padding-top: 100%;
}
.inner {
background-color: blue;
height: 3px;
width: 100%;
}
<div class='outer'>
<div class='middle'>
A
<div class='inner'>
</div>
</div>
</div>
<div class='outer' style='width:100px'>
<div class='middle'>
B
<div class='inner'>
</div>
</div>
</div>
<div class='outer' style='height:400px'>
<div class='middle'>
C
<div class='inner'>
</div>
</div>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…