我正在尝试使用overflow-x: scroll和white-space: nowrap来创建一个具有(平铺)背景图像的水平滚动窗格。该窗格跨越任意数量的元素。
CSS:
.frame {
overflow-x: scroll;
}
.pane {
background-image: url(free-tile-floor-texture.jpg);
background-repeat: repeat;
white-space: nowrap;
}
.item {
display: inline-block;
width: 150px;
height: 50px;
background-color: grey;
}
HTML:
<div class="frame">
<div class="pane">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</div>
我希望背景图铺满整个面板,包括其中所有元素的宽度。目前它只填充到框架的宽度。问题看起来是面板宽度属性导致的-它不会自适应面板内容的总宽度。
当然,手动调整宽度属性可以解决问题,但我需要它能够动态调整。
如何让面板的背景图填充整个面板的宽度?还有其他实现同样效果的方法吗?