编程练习 为啥我对.top设置padding-top后 .center也跟着一起改变呢
来源:3-5 编程练习
muke_xinke
2020-07-17 18:58:30
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.content{
width:800px;
height:400px;
background-color: skyblue;
}
.top{
width:400px;
height:200px;
background-color: yellow;
margin-left:200px;
margin-top:100px;
box-sizing:border-box;
}
</style>
</head>
<body>
<div class="content">
<div class="top"></div>
</div>
</body>
</html>

我知道正确答案 只是这样尝试了下 不太懂为什么
1回答
同学你好,同学描述的上外边距吧( margin-top)。如果是,则当一个盒子如果没有上边距(padding-top)和上边框(border-top),那么这个盒子的上边距会和其内部文档流中的第一个子元素的上边距重叠。同学可以为父元素设置上边距(padding-top)。 如下图所示:

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
相似问题