作者:小蚊子 | 来源:互联网 | 2023-05-18 19:12
Ihaveaflexbox(flex-direction:row)with2columnsofcontentandafixedheight.Iwanttheleft
I have a flexbox
(flex-direction: row
) with 2 columns of content and a fixed height. I want the left and right column to have a red and blue background respectively. If either of the columns overflow, the flexbox
's scrollbar appears (the overflowed part is still red/blue). If a column's content height is less than the flexbox
's height, the space below should still be red/blue.
我有一个有两栏内容和固定高度的弹性(弹性方向:行)。我希望左栏和右栏分别有红色和蓝色背景。如果任一列溢出,flexbox的滚动条就会出现(溢出部分仍然是红色/蓝色)。如果一个列的内容高度小于flexbox的高度,下面的空间仍然应该是红色/蓝色的。
Without using gradient colors or Javascript, how can I achieve this effect?
不使用渐变颜色或Javascript,如何实现这种效果?
Demo (I want the gray part to be blue):
演示(我希望灰色部分是蓝色的):
#c1 {
background-color: gray;
display: flex;
height: 200px;
overflow-y: auto;
align-items: baseline;
}
#left {
flex: 1;
background-color: red;
}
#right {
flex: 1;
background-color: blue;
}
line
line
line
line
line
line
line
line
line
line
line
line
line
line
EDIT
Methods that don't work:
不工作的方法:
- Setting
align-items: stretch
: overflowed part will be gray
- 设置对齐项:拉伸:溢出部分为灰色
- Add a
position: absolute
div
that overlays the flexbox
, solely for the background: this div
will have the wrong width if the scrollbar is visible.
- 添加一个位置:覆盖flexbox的绝对div,仅用于背景:如果滚动条是可见的,那么这个div的宽度将会是错误的。
5 个解决方案