简体   繁体   English

如何让我的动画图像覆盖所有背景?

[英]how can I make my animated image cover all background?

I've got a an image I'm using as a background that is animated in CSS, but it is push all of my content to the bottom of the page with plain white background.我有一张图片用作背景,在 CSS 中设置动画,但它将我的所有内容推送到带有纯白色背景的页面底部。 Does anyone know how I can get it to act more of an animated wallpaper so my content isn't pushed down?有谁知道我怎样才能让它表现得更像一个动画墙纸,这样我的内容就不会被推倒?

 #map { height: 400px; width: 400px; margin: 0 auto; } .check { text-align: center; } h3, h2, h1, a { text-align: center; background-color: transparent; } #sky { overflow: hidden; } #clouds { width: 200%; height: 1000px; background-image: url('https://images.unsplash.com/photo-1455735459330-969b65c65b1c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1652&q=80'); -webkit-animation: movingclouds 25s linear infinite; -moz-animation: movingclouds 25s linear infinite; -o-animation: movingclouds 25s linear infinite; } @keyframes movingclouds { 0% { margin-left: 0%; } 100% { margin-left: -100%; } }
 <div id="sky"> <div id="clouds"></div> </div>

Move the animation to the background position.将动画移动到背景位置。 This way, it will animate behind whatever is on top of it.这样,它就会在它上面的任何东西后面动画。 In this case, I've moved the background to the body, but you can use absolute/relative position as well.在这种情况下,我已将背景移到正文,但您也可以使用绝对/相对位置。

By animating the margin, you push everything to one side, not just the background.通过设置边距动画,您可以将所有内容推到一侧,而不仅仅是背景。

body {

  background-image: url('https://images.unsplash.com/photo-1455735459330-969b65c65b1c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1652&q=80');
  -webkit-animation: movingclouds 25s linear infinite;
  -moz-animation: movingclouds 25s linear infinite;
  -o-animation: movingclouds 25s linear infinite;
}

@keyframes movingclouds {
  0% {
    background-position: 0%;
  }
  100% {
    background-position: -100%;
  }
}

Working example: https://jsbin.com/ruyemijasi/edit?html,css,js,output工作示例: https : //jsbin.com/ruyemijasi/edit?html,css,js,output

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

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