CSS Margin In Percentage

July 12, 2012

Okay, this is funny; but only if it doesn't come in the way of you getting things done on time. I was trying to assign percentage margin to a <div> and it kept throwing me off on the calculations. A bit of googling led me to this explanation. If you are giving padding/margin in percentage, due to some out-of-the-world reason it would calculate on the basis of the width of the parent element; whether you are calculating left-right values for margin/padding, or the top-bottom ones. It beats me as to why is it this way. Let me know if you know the answer. Back to work!