南城& 2022-08-31 13:21 采纳率: 70.6%
浏览 59
已结题

想要让b距离顶部,为什么a会跟着一起

三个盒子a,b,c;b在a里面,我调了b的margin-top为300px,想要让b距离顶部300,但是为什么a会跟着一起动?
代码
  <style>
        *{
            padding: 0;
            margin: 0;
        }
        .c{
            position: fixed;
            width: 100%;
            height: 80px;
            top: 0px;
            background-color: green;
        }
        .a{
           
            width: 700px;
            height: 3000px;
            background-color: pink;
            margin: 0 auto;
        }
        .b{
            width: 200px;
            height: 200px;
            background-color: yellow;
            margin-top: 200px;
        }
       
    </style>
</head>
<body>
     <div class="c"></div>
     <div class="a">
        <div class="b"></div>

     </div>
     
</body>

运行结果及报错内容

img

  • 写回答

3条回答 默认 最新

  • fruge365 2022-09-01 16:26
    关注

    触发bfc了,b在a里面,所以margin-top向上传递了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月11日
  • 已采纳回答 9月3日
  • 创建了问题 8月31日

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应