【发布时间】:2023-04-10 01:46:02
【问题描述】:
我正在尝试使用相对于祖父元素宽度的百分比来设置某些元素的宽度。像这样。
<style>
.grand{width:1000px; overflow:hidden;}
.parent{width:2000px; position:relative}
.child1{float:left; width:50%; height:200px; background-color:blue;}
.child2{float:left; width:50%; height:200px; background-color:green;}
</style>
<div class="grand">
<div class="parent">
<div class="child1"></div>
<div class="child2"></div>
</div>
</div>
但我不知道如何做到这一点,我怎样才能让子元素直接引用它的祖父元素而不是直接父元素? (在这种情况下,如果我将子元素宽度设置为 50%,它必须是 500 像素,而不是 1000 像素。)
有没有可能的方法来做到这一点?
【问题讨论】:
标签: javascript jquery css width