html – 为什么margin-top无法使黄色框变亮?

html – 为什么margin-top无法使黄色框变亮?,第1张

概述参见英文答案 > Why does this CSS margin-top style not work?                                    11个 不要介意注释掉的行.我正在尝试使用盒子模型,但似乎无法弄清楚为什么我不能使用margin-top将黄色盒子放下一点?我可以使用margin-left让它向右移动,这对我来说似乎很奇怪…谢谢. 我想明白为什么会这样: 参见英文答案 > Why does this CSS margin-top style not work?11个
不要介意注释掉的行.我正在尝试使用盒子模型,但似乎无法弄清楚为什么我不能使用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 >        <div ></div>    </div>
解决方法 这是由于 margin collapsing发生的 – 所以边框,填充到父元素或内联内容(任何内联元素)将关闭边距折叠.

见下面的演示:

.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 >  <div ></div></div>
总结

以上是内存溢出为你收集整理的html – 为什么margin-top无法使黄色框变亮?全部内容,希望文章能够帮你解决html – 为什么margin-top无法使黄色框变亮?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1128410.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存