top not work to get the yellow box down?

This question already has an answer here:

  • Why does this CSS margin-top style not work? 11 answers

  • This happens due to margin collapsing - so a border , padding to the parent element or inline content (any inline element) will switch off margin collapsing.

    See demo below:

    .largebox {
      width: 800px;
      height: 350px;
      background-color: #00f;
      margin-left: 10px;
      border: 1px solid; /*ADDED THIS*/
    
    }
    .box1 {
      width: 250px;
      height: 300px;
      background-color: #ff0;
      margin-left: 50px;
      margin-top: 25px;
    }
    <div class="largebox">
      <div class="box1"></div>
    
    </div>

    Use display:inline-block; in box1

    .largebox {
        width: 800px;
        height: 350px;
        background-color: #00f;
        //padding-left: 50px;
        margin-left: 10px;
        //border: 2px solid black;
    }
    
    .box1 {
        width: 250px;
        height: 300px;
        background-color: #ff0;
        //display: inline;
        //float: left;
        //margin-right: 0px;
        margin-left: 50px;
        margin-top: 25px;
        display:inline-block;
     }
     
     
    <div class="largebox">
            <div class="box1"></div>
    
        </div>

    You can try using position:absolute; in .box1 like this:

    .box1{
        position:absolute;
    }
    
    链接地址: http://www.djcxy.com/p/21990.html

    上一篇: PHP中基于令牌的身份验证

    下一篇: 顶部不工作让黄色框失望?