为什么绝对定位的 DIV 不继承其父级的宽度?分区有
div {
position: absolute;
top:100px;
}
<html>
<body>
<div>This DIV</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在静态定位中,DIV 占据所有可用空间,DIV 的绝对宽度与其内容的长度一样长。
div 的默认宽度是 auto。它自动是内部内容的宽度。它不继承父级的宽度。为此,您需要指定 div 宽度的继承
div {
position: absolute;
top:100px;
width: inherit;
}
Run Code Online (Sandbox Code Playgroud)
http://codepen.io/anon/pen/BLPNrm
| 归档时间: |
|
| 查看次数: |
12880 次 |
| 最近记录: |