Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css/html: padding in % doesn't make sense [duplicate]

Tags:

html

css

Consider the following html

<div id="parent">
    <div id="child"/>
</div>

I've given the parent a height of 100px. The child has a height of 100% and a padding of "10% 0". In CSS:

* {
    box-sizing: border-box;
}
#parent {
    height: 100px ;
}
#child {
    height: 100%;
    padding: 10% 0;
}

Or checkout this jsfiddle. Anyway, from the above I would expect the child div to have a top/bottom border of 10px (10% of 100px). But it is 31.5px. Can someone explain why this happens and how I can achieve what I want ?

Thanks a lot!

like image 624
Jeanluca Scaljeri Avatar asked Dec 02 '25 05:12

Jeanluca Scaljeri


1 Answers

Any percentage value will be calculated using the width of the element.

like image 91
Jan Heinrich Reimer Avatar answered Dec 03 '25 19:12

Jan Heinrich Reimer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!