Why does this CSS margin-top style not work?

前端 未结 12 1959
醉梦人生
醉梦人生 2020-11-21 04:54

I try to add margin values on a div inside another div. All works fine except the top value, it seems to be ignored. But why?

What I expected:
<

12条回答
  •  粉色の甜心
    2020-11-21 05:31

    Use padding-top:50pxfor outer div. Something like this:

    #outer {
        width:500px; 
        height:200px; 
        background:#FFCCCC;
        margin:50px auto 0 auto;
        display:table;}
    

    Note: padding will increase the size of your div. In this case if the size of your div is important, I mean if it must have a specific height. decrease the height by 50px.:

    #outer {
        width:500px; 
        height:150px; 
        background:#FFCCCC;
        margin:50px auto 0 auto;
        display:table;}
    

提交回复
热议问题