#outer
和#inner
必须同时为position:absolute
或fixed
。
如何使#inner
中的100%
值相对于#outer
的宽度减去其填充(例如,类似于框架)而不会溢出#inner
?
html, body {
height: 100%;
margin: 0;
width: 100%;
}
#outer {
background: red;
height: 50%;
padding: 20px;
position: absolute;
width: 50%;
}
#inner {
background: yellow;
height: 100%;
position: absolute;
width: 100%;
}
<div id="outer">
<div id="inner"></div>
</div>