为什么 margin-top 不能将黄色框放下?

Why does margin-top not work to get the yellow box down?

不要介意注释掉的行。我正在试验盒子模型,但似乎无法弄清楚为什么我不能使用 margin-top 将黄色盒子稍微放下一点?我可以使用 margin-left 让它向右移动,所以这对我来说很奇怪......谢谢。

我想了解为什么会这样:)

.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;
 }
    <div class="largebox">
        <div class="box1"></div>

    </div>

box1

中使用display:inline-block;

.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>

您可以像这样在 .box1 中使用 position:absolute;

.box1{
    position:absolute;
}

发生 由于 margin collapsing - 所以 border, padding 父元素 inline 内容(任何 inline 元素)将关闭边距折叠。

参见下面的演示:

.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>