gpt4 book ai didi

css - 绝对定位元素展开父元素

转载 作者:行者123 更新时间:2023-11-28 14:43:50 25 4
gpt4 key购买 nike

enter link description here

html,
body {
margin: 0;
padding: 0;
}

.div1 {
height: 500px;
position: relative;
background-color: red;
}

.div2 {
width: 100px;
height: 100px;
background-color: green;
position: absolute;
right: -80px;
top: 0;
}
<div class="div1">
<div class="div2"></div>
</div>

dom'div2'是绝对定位元素,dom'div1'是相对定位元素,当我将'div2'的left属性设置为'-80px'时,它推开了父dom,并且让滚动条显示,谁知道为什么....感谢帮助我!

最佳答案

absolute 属性是相对于 DOM 的祖先元素设置的,因此 -80px 在第一个 div 之外,因此它被“推出”div1。一种可能的解决方案是使用 -80 的恭维语或相对语。

关于css - 绝对定位元素展开父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52564328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com