为什么绝对定位的DIV不继承其父级的宽度? Div 有
div {
position: absolute;
top:100px;
}
<html>
<body>
<div>This DIV</div>
</body>
</html>
在静态定位中,DIV 占用所有可用空间,DIV 的绝对宽度与其内容的长度一样长。
最佳答案
div 的默认宽度是自动的。它自动是里面内容的宽度。它不继承父级的宽度。为此,您需要在 div 的宽度上指定继承
div {
position: absolute;
top:100px;
width: inherit;
}
关于html - 为什么绝对定位的DIV不继承父级的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40031450/