div margin | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

div margin

when i create a div"inner" inside another div"outer" the inner div can't get margin top.. what is the error ?

1st Jan 2018, 9:48 PM
Abdullah Mohamed
6 Answers
+ 4
In your .in you have margin:20px auto; Remove the word 'auto' as it looks like it's confusing it. Then set the 'position' to 'relative' for .out and 'absolute' for .in. I won't attempt to explain positioning as I'm still learning it myself, but here's a handy reference: https://www.w3schools.com/css/css_positioning.asp
2nd Jan 2018, 7:15 PM
Duncan
Duncan - avatar
+ 7
Abutted margins share (overlap), so e.g.: the bottom margin of one element would merge with the top margin of another. If that's not helpful, can you link your code (CodePlayground)?
1st Jan 2018, 9:54 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
Another tip, whilst developing, it can be a good idea to turn on borders and color your div's differently. It will really help you visualise your layout.
2nd Jan 2018, 12:40 AM
Duncan
Duncan - avatar
+ 2
thanks all for replying I have fixed it
2nd Jan 2018, 10:03 PM
Abdullah Mohamed
+ 1
Use padding from the outer <div> element instead. Good answer @Kirk
1st Jan 2018, 10:28 PM
Andreas K
Andreas K - avatar
2nd Jan 2018, 3:34 PM
Abdullah Mohamed