微信小程序css margin 怪异问题
如图及代码所示,当增加.list
上边距时,比如上边距由20变为120 margin: 120px 0 0 0;
,就会出现顶部bar
白色区域下拉的情况,这是什么原因?
<view class="container">
<view class="list">
66666666666666666666666666666
</view>
</view>
.container {
background-color: #e98737;
color: #333;
font-size: 16px;
height: 100%;
}
.list {
margin: 20px 0 0 0;
padding: 10px;
background-color: rgb(161, 224, 228);
border-radius: 5px;
}
这是一个css margin 塌陷问题,不止小程序会有,具体见margin塌陷
.container
没设置高度时.list
的margin-top没有把.container
撑开.container
设置了高度时.list
的margin-top跑到.container
外面去了代码片段:https://developers.weixin.qq.com/s/flaLmDmB70x9
代码片段的margin塌陷效果: