【发布时间】:2017-06-11 02:36:02
【问题描述】:
我试图弄清楚是否有某种方法可以使百分比引用父级的父级。
在下面的示例中,我希望文本具有绿色 div 的宽度,而不是其直接父级(即白色)的宽度。
#fluid {
width: 75vw;
height: 75vh;
background: olive;
position: absolute;
}
#fixed {
width: 100px;
height: 100px;
background: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#text {
color: black;
width: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin: 0;
}
<div id="fluid">
<article id="fixed">
<h3 id="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</h3>
</article>
</div>
有什么方法可以让我只使用 CSS 来实现这一点吗?
【问题讨论】:
标签: html css parent-child percentage