简体   繁体   English

CSS背景位置使用多个背景

[英]CSS background-position using multiple background

Currently I am using multiple backgrounds to create panel with fixed top and bottom images, and center image to reapeat vertically, as content continues. 目前,我正在使用多个背景来创建面板,该面板具有固定的顶部和底部图像,并且随着内容的继续,中心图像垂直重复显示。

<div style="
background-image: url(top.png), url(center.png), url(bottom.png);
background-position: top, center, bottom;
background-repeat: no-repeat, repeat-y, no-repeat;
width:242px;
">
fgffg<br />
fgffg<br />
fgffg<br />
fgffg<br />
fgffg<br />
fgffg<br />
fgffg<br />
fgffg
</div>

The problem I encounter is that using no-repeat, repeat-y, no-repeat bottom image is SKIPPED. 我遇到的问题是,使用不重复,重复y,不重复的底部图像已被跳过。 Center image repeats itself to the end! 中心图像重复到最后!

I need to figure out (and do it elegantly, cleanly) how make middle part repeat itself by axis y, but also to leave space for bottom part to end my div block nicely. 我需要弄清楚(并优雅地,干净地做)如何使中间部分沿y轴重复,还要为底部留出空间以很好地结束div块。

Thanks! 谢谢!

Probably the problem comes from the center image occupying all the space. 问题可能出在中心图像占据所有空间上。

Since it is layered above the bottom, it makes it not visible. 由于它位于底部上方,因此使其不可见。

Just change the order: repeating image in the first rendered layer (the last one in the list !) then the other 2 只需更改顺序:在第一个渲染层(列表中的最后一个!)中重复图像,然后在其他2层中重复

background-image: url(top.png), url(bottom.png), url(center.png);
background-position: top, bottom, center;
background-repeat: no-repeat, no-repeat, repeat-y;

Demo 演示版

The images are placed as floats. 图像放置为浮点。 When you place top image then centre image, it covers the spaces available, leaving no space for the bottom image. 当您放置顶部图像然后放置中心图像时,它将覆盖可用空间,而底部图像则没有空间。

Thus, changing the order works very well. 因此,更改顺序非常有效。 The top and bottom images are placed with no-repeat then the remaining spaces are filled with centre image with vertical repetition. 顶部和底部图像无重复放置,然后其余空间以垂直重复的中心图像填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM