Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I add a margin to a nested DIV, it causes the parent DIV to receive the margin instead, unless I give the parent DIV a border. Why?

Has anyone else ever ran across this? This is the second time it's come up in as many years and I am not sure the "correct" way to solve it.

I can achieve the same results with padding in the child, but it just makes no sense.

Testing in Safari/FF.

like image 401
Jazzy Avatar asked Dec 21 '22 22:12

Jazzy


1 Answers

I usually solve this problem by setting display: inline-block on outer div. It'll make outer div to occupy exactly the space necessary to display its content.

An example, showing the difference.

like image 154
Nikita Rybak Avatar answered Dec 24 '22 12:12

Nikita Rybak