关于嵌套absolute布局的padding-bottom问题

当父元素使用relative且子元素为absolute布局时,子元素高度超出父元素不会撑开父盒子,但会隐形撑开其内容区域。在固定高度的父元素中,子元素溢出,但仍然遵循盒模型规则。在IE浏览器下,父元素的padding-bottom和子元素的margin-bottom可能失效。

流动布局时

父元素含有50px的padding,因为子元素溢出,所以padding-bottom没有表现出来。


但实际上,子元素为了保证处于父盒子的content之中,已经把父盒子撑开了。只是因为这里强制对父盒子设置了高度,所以子元素溢出。      

我们将滚动条拉到底部,可以发现子元素确实仍在父元素的padding之内。

因此可以说:流动布局时,父元素设置了固定高,子元素如果高于父盒子,它将溢出,但它相当于隐性地将父盒子撑开了,仍然满足盒模型的规则,只是要通过拖动滚动条才能看出。


父元素relative, 子元素absolute

父元素relative+子元素absolute,子元素脱离了父盒子的文档流,不设置left和right的话,从头部开始处于默认的位置(父盒子content的左上角),所以它在padding-top和padding-left之内。它的高度比父盒子大,但不会撑开父盒子,相当于z-index位于父盒子的上层,一直向下铺展开,与父盒子的padding-bottom没有关系。


滚动条拖到最下面,也只是让我们看到子元素的最底部,父元素的盒子依然在原地岿然不动。


注意:IE浏览器下,父元素的padding-bottom和子元素的margin-bottom都将消失。





@namespace: flow-my-submissions; @import (reference) '@/global/theme/variables.less'; .@{namespace} { &-pageContainer { display: flex; flex-direction: column; height: 100%; overflow-x: hidden; .ant-table-wrapper { overflow: hidden; } --white-color: #fff; --primary-color: #006eff; } &-proSearch { background-color: #fff; padding: 8px; border-radius: 4px; .ant-row { margin: 0 !important; .ant-col { padding-left: 0 !important; padding-right: 4px; .ant-select-sm-style(); .ant-form-item-label { padding: 0 !important; } } } } &-tableContainerCurrent { min-height: 400px; // margin-top: 10px; border-radius: 4px; height: 100%; flex: 1; overflow: hidden; .ant-table { background-color: transparent; } .ant-pro-table .ant-table-wrapper .ant-pagination, .ant-table-pagination { margin-block-end: 8px !important; } .ant-table-body { background: var(--ant-color-bg-container); padding-bottom: 1px; &::-webkit-scrollbar-thumb { background: rgba(48, 54, 62, 0); &:hover { background: rgba(48, 54, 62, 0.3); } } &:hover::-webkit-scrollbar-thumb { background: rgba(48, 54, 62, 0.5); } } .ant-table-placeholder { height: 80%; .ant-table-cell { border-bottom: 0; } } .ant-pro-card { background-clip: content-box !important; margin: 8px 0 0 0 !important; .ant-pro-card-body { position: relative; min-height: 40px !important; background-color: #fff; border-radius: 4px; .ant-pagination { margin: 10px; } .ant-pro-table-alert { position: absolute; left: 10px; bottom: 10px; margin: 0; z-index: 1; background: none; .ant-pro-table-alert-container { padding-block: 0px; padding-inline: 0px; } } } } } &-buttonContainer { padding: 0; max-width: 100%; span { color: var(--primary-color); } } } less文件中@namespace这个的作用
08-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值