[英]Make parent div expand beyond window to wrap all children
While this sounds like a pretty simple problem to solve, I have not found a way to do this without using Javascript. 尽管这听起来像是一个非常简单的问题,但我没有找到一种无需使用Javascript即可实现的方法。
Consider this example: https://jsfiddle.net/oopssam8/1/ 考虑以下示例: https : //jsfiddle.net/oopssam8/1/
<div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
div > div {
width: 200px;
flex-shrink: 0;
height: 200px;
background: red;
}
body > div {
display: flex;
flex-flow: row nowrap;
}
As you can see, the red boxes expand beyond the window. 如您所见,红色框扩展到窗口之外。 Each box is 200px wide, and so when when inspecting their parent, I expect to see a width of 2000px (there are 10 red boxes).
每个框的宽度为200像素,因此在检查其父级时,我希望看到的宽度为2000像素(有10个红色框)。 The computed width of the parent div does not extent beyond the window width.
父div的计算宽度不会超出窗口宽度。
Is there any way I could make the parent div expand beyond the window and wrap all child element? 有什么办法可以使父div扩展到窗口之外并包装所有子元素?
You could set the value of the width on the container div to: width: fit-content;
您可以将容器div上的width值设置为:
width: fit-content;
(with additional vendor prefixes, like in the example below) (带有其他供应商前缀,如下面的示例所示)
Here's the working example: 这是工作示例:
div > div { width: 200px; flex-shrink: 0; height: 200px; background: red; } body > div { display: flex; flex-flow: row nowrap; width: -webkit-fit-content; width: -moz-fit-content; width: fit-content; }
<div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.