【发布时间】:2021-12-14 04:38:22
【问题描述】:
据我所知,孩子的宽度百分比标准是父母的内容框(只有内容,没有填充或边距。)。因此,如果父项中有一个填充并且子项的宽度为 100%,则子项的宽度小于父项。但是如果我将孩子定位为绝对而父母定位为相对,无论父母的填充和边距如何,孩子的宽度都等于父母的宽度。像这样:
<div class="first">HI
<div class="second">
HELLO
</div>
</div>
css代码
.first{
background-color: yellow;
width:100px;
height:100px;
padding:10%;
position:relative;
}
.second{
background-color: blue;
position:absolute;
width: 100%;
height:100%;
opacity:40%;
}
尽管父母的位置和相对所以孩子完全依赖于'.first'。这种情况下孩子的宽度标准是多少?
【问题讨论】:
标签: html css position css-position absolute