Layout. Margin-top nested divas. A strange bug?

0 like 0 dislike
14 views
Hello.

Faced with the problem
<div id="d1">
<div id="d2">
ee
</div>
</div>


#d2{ margin-top:10px; }




Reason is not shifted d2 inside of d1, and d1 pulls from the top to 10px


What's the problem?
by | 14 views

4 Answers

0 like 0 dislike
Margins shrink, this is normal. Solutions:
1)
#d2 {
margin-top: 10px;
display: inline-block; /* or inline, table, table-cell, etc */
}
2)
#d1 {
padding-top: 10px;
}
3)
#d2 {
margin-top: 10px;
position: absolute;
}
by
0 like 0 dislike
by
0 like 0 dislike
This is a true collapse fields in accordance with the standard. To get around this, you can, for example, at m2 instead of margin use padding from m1.
by
0 like 0 dislike
Thanks for the replies. Didn't know that some of the collapse.
by

Related questions

0 like 0 dislike
1 answer
asked May 21, 2019 by emin313
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
28,804 users