如何使云图像在CSS中移动,而不会与HTML中的书面内容一起移动?

发布于 2025-02-09 16:59:29 字数 1386 浏览 0 评论 0原文

我希望云图像在背景中移动而不会附加到书面内容上。这是我到目前为止所做的。我尝试了其他方法,但是我仍然有同样的问题。

.intro {
  background-image: url(https://via.placeholder.com/50.jpg);
  position: relative;
  background-repeat: round;
  animation: animatedBackground 5s linear infinite;
}

@keyframes animatedBackground {
  0% {
    background-position: 0 0;
  }
  50% {
    background-position: -20px 0;
  }
  100% {
    background-position: 20px 0;
  }
}
<section class="intro" id="zen-intro">
  <header role="banner">
    <h1>CSS Zen Garden</h1>
    <h2>The Beauty of <abbr title="Cascading Style Sheets">CSS</abbr> Design</h2>
  </header>

  <div class="summary" id="zen-summary" role="article">
    <p>A demonstration of what can be accomplished through <abbr title="Cascading Style Sheets">CSS</abbr>-based design. Select any style sheet from the list to load it into this page.</p>
    <p>Download the example <a href="/examples/index" title="This page's source HTML code, not to be modified.">html file</a> and <a href="/examples/style.css" title="This page's sample CSS, the file you may modify.">css file</a></p>
  </div>

I want the cloud image to move in the background without being attached to the written content. This is what I have done so far. I have attempted other ways, but I still have the same problem.

.intro {
  background-image: url(https://via.placeholder.com/50.jpg);
  position: relative;
  background-repeat: round;
  animation: animatedBackground 5s linear infinite;
}

@keyframes animatedBackground {
  0% {
    background-position: 0 0;
  }
  50% {
    background-position: -20px 0;
  }
  100% {
    background-position: 20px 0;
  }
}
<section class="intro" id="zen-intro">
  <header role="banner">
    <h1>CSS Zen Garden</h1>
    <h2>The Beauty of <abbr title="Cascading Style Sheets">CSS</abbr> Design</h2>
  </header>

  <div class="summary" id="zen-summary" role="article">
    <p>A demonstration of what can be accomplished through <abbr title="Cascading Style Sheets">CSS</abbr>-based design. Select any style sheet from the list to load it into this page.</p>
    <p>Download the example <a href="/examples/index" title="This page's source HTML code, not to be modified.">html file</a> and <a href="/examples/style.css" title="This page's sample CSS, the file you may modify.">css file</a></p>
  </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文