简体   繁体   English

CSS背景重复与多个图像

[英]CSS background-repeat with multiple images

How can I use background-repeat with multiple images? 如何对多个图像使用背景重复功能? The primary background image is static and only sits at the top of the unscrolled page. 主要背景图片是静态的,仅位于未滚动页面的顶部。

Once the user starts to scroll down on longer pages, there is a secondary background image than blends in with the first image. 一旦用户开始向下滚动较长的页面,就会有一个辅助背景图像,而不是与第一个图像融合在一起。

This image repeats infinitely (if necessary) for long pages. 对于长页面,此图像将无限重复(如有必要)。

How can I do this? 我怎样才能做到这一点?

This is what I have tried: 这是我尝试过的:

background-image:
    url(../images/background/large/static.png),
    url(../images/background/large/repeat.png);
background-repeat:
    no-repeat,
    repeat-y;
background-position:
    0px top,
    600px top;

The static.png background page is on top and displays from 0 to 600px. static.png背景页面位于顶部,显示范围为0到600px。 The repeat.png then starts at 600px and keeps repeating down to infinity if necessary. 然后,repeat.png从600px开始,并在必要时继续向下重复到无穷大。 The static page should only display once at the very top. 静态页面仅在顶部显示一次。 Any suggestions? 有什么建议么? Thank you! 谢谢!

I think one big problem is, background-repeat is only applied once and to both images. 我认为一个大问题是,背景重复仅适用于一次和两次图像。

Got everything working. 使一切正常。 The issue was with the background-position. 问题在于背景问题。 I did not understand the syntax. 我不了解语法。 600px from the left and align to the top is what it says in the above example. 在上面的示例中,它从左侧对齐600px,并与顶部对齐。 I thought its meant 600px from the top. 我认为这意味着距顶部600像素。 When I tried using the real number it was putting the image way off the screen at right making it feel like it wasn't working. 当我尝试使用实数时,它会将图像从屏幕上移到正确的位置,使它感觉好像不起作用。 I understand the syntax now and all is working perfectly. 我现在了解语法,并且一切正常。 Thanks! 谢谢!

background-image:
    url(../images/background/large/static.png),
    url(../images/background/large/repeat.png);
background-repeat:
    no-repeat,
    repeat-y;
background-position:
    left top,
    left 600px;

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

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