gpt4 book ai didi

javascript - 是否可以使容器内的元素大于容器?

转载 作者:太空宇宙 更新时间:2023-11-03 22:30:07 24 4
gpt4 key购买 nike

假设我有一个宽度为 900px 的容器,里面的所有帖子都是 900px。

我想让第一个成为 100%(不是 900px 但和屏幕一样大)。

这可能吗?

#container { width: 900px; background: red; }
.post { width: 900px; height: 50px; background: yellow; margin: 0 0 10px; }
.post:first-child { background: green; }
<div id="container">
<div class="post">Post 1</div>
<div class="post">Post 2</div>
<div class="post">Post 3</div>
</div>

最佳答案

对于给定的样式,100% 的宽度将与您的容器 一样宽,因此您可以使用 viewport units ,例如

.post:first-child { width : 100vw; }

(1vw 等于视口(viewport)宽度的 1%)

关于javascript - 是否可以使容器内的元素大于容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48864547/

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