CSS Margin In Percentage

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!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s