我正在尝试使用也绝对定位的flexbox创建一个表。
每行都是display: flex
的标准div
每行中的每个项目都是弯曲项目。
请注意,任何地方都没有设置宽度。
为什么我的背景颜色如此混乱。
我注意到如果行中有更多文本并且背景是从背景计算的,那么背景会进一步扩展,除了背景不包括整行之外。
尝试显示:inline-flex
和background-size: cover
无效
https://jsfiddle.net/66f9s2kp/7/
<div style="z-index: 3; position: absolute; top: 50px; left: 50%; transform: translateX(-50%);">
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 100);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">sume stufff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
</div>
<div style="z-index: 3; position: absolute; top: 150px; left: 50%; transform: translateX(-50%);">
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 100);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">so much stuff tipsois asdfasdfasdfasdfasdfasdfthinggyh stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
</div>
帮助,为了我的理智,
谢谢,
赖安
答案 0 :(得分:1)
使用<data src="abcdef...5000 characters..." />
代替width
,父母将填充父母,而不是从父母那里溢出的孩子。
flex-basis
答案 1 :(得分:1)
您的主要div容器绝对定位。
如您所述:“请注意,任何地方都没有设置宽度。”
在这种情况下,绝对定位的div的宽度将由其内容决定。
div[style*="absolute"] {
border: 2px dashed red;
}
<div style="z-index: 3; position: absolute; top: 50px; left: 50%; transform: translateX(-50%);">
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 100);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">sume stufff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
</div>
<div style="z-index: 3; position: absolute; top: 150px; left: 50%; transform: translateX(-50%);">
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 100);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">so much stuff tipsois yh stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
</div>
Flex项目溢出容器。但由于背景颜色是在容器上设置的,因此颜色以容器结束。
一种解决方案是在绝对定位的容器上设置宽度:
div[style*="absolute"] {
border: 2px dashed red;
width: 1000px; /* the sum of flex item widths */
/* or width: 100% */
/* or left: 0; right: 0; */
}
* {
box-sizing: border-box;
}
<div style="z-index: 3; position: absolute; top: 50px; left: 50%; transform: translateX(-50%);">
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 100);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">sume stufff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
</div>
如果您不想在容器上设置宽度,另一种解决方案是将背景颜色应用于项目,而不是容器。
div[style*="absolute"] > div:nth-child(odd) > div {
background-color: rgb(173, 216, 230) !important;
}
div[style*="absolute"] > div:nth-child(even) > div {
background-color: rgb(173, 216, 100) !important;
}
<div style="z-index: 3; position: absolute; top: 50px; left: 50%; transform: translateX(-50%);">
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 100);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">tesdfxt stuff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
<div style="display: flex; background-color: rgb(173, 216, 230);">
<div style="flex: 0 0 200px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: left; white-space: nowrap;">sume stufff</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">more</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">29</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">Standard</div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 100px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;"></div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
<div style="flex: 0 0 75px; font-family: monospace; background-color: transparent; border: 1px solid black; overflow: hidden; text-align: center; white-space: nowrap;">0</div>
</div>
</div>