gpt4 book ai didi

html - 强制子 div 宽度匹配父 div 宽度

转载 作者:太空宇宙 更新时间:2023-11-04 13:39:03 25 4
gpt4 key购买 nike

我有以下 HTML 元素。

<div id="theparent">
<div class="thechild">
<div class="anotherchild"></div>
</div>
</div>

以及这些元素的 CSS。

#theparent{width: 90%;}
.thechild{width: 100%; padding: 10px;}
.anotherchild{}

现在我想要的是 .anotherchild div 宽度必须等于或等于 .theparent div 的宽度,同时保持 的填充。 thechild div,该怎么做?非常感谢任何建议、建议和想法。

最佳答案

由于 .thechild 的填充是已知的,您可以使用 CSS3 calc()函数将该已知值添加到 100% 可能的任何值,并用负余量修复偏移量。

.anotherchild{
margin-left:-10px;
width:calc(100% + 20px);
}

关于html - 强制子 div 宽度匹配父 div 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com