html - 在 css 动画之上叠加图像

标签 html css background-image

我正在尝试在此 CSS 动画之上叠加图像。我只是想让它坐在它的中间。我试过使用 z-index 和不同的位置,但我似乎无法让它显示出来。我还想让颜色在鼠标移过不同点时发生变化。

body {
  margin: 0;
  padding: 0;
}

.container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to right, #FFB6C1 10%, #FF69B4 51%, #FFB6C1 100%);
  background-size: cover;
  animation: animate 60s linear infinite loop;
}



.clouds {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url(https://image.ibb.co/cbYTjf/cloud.png);
    animation: animate 60s linear infinite;
  z-index:1;
}
.logo{
  background-image:url(https://i.vgy.me/7FcUbx.jpg)
    z-index: 10;
  position:absolute;
}

@keyframes animate {

  0% {
    background-position: 0px;
  }
  100% {
     background-position: 1063px;
    
  }

}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title> Clouds </title>

  <link rel="stylesheet" href="clouds.css">
</head>

<body>
  <div class= "container">
  </div>
  <div class="background-color"></div>

  <div class="clouds">
    <div class="logo">
    
  </div>
</body>

最佳答案

您可以通过多种方式实现这一目标。我会考虑使用伪元素作为叠加层或其他东西,但这是一种方法。

我看到的主要问题是您需要为 Logo 定义高度和宽度。

Codepen 如果你愿意的话: https://codepen.io/zenRyoku/pen/rgWNQo?editors=1100

body {
  height: 100vh;
  width: 100%;
  margin: 0;
  padding: 0;
}

.container {
  position: relative;
  width: 100%;
  height: 100%;
  background: linear-gradient(to right, #FFB6C1 10%, #FF69B4 51%, #FFB6C1 100%);
  background-size: cover;
  animation: animate 60s linear infinite loop;
}

.clouds {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('https://image.ibb.co/cbYTjf/cloud.png');
  animation: animate 60s linear infinite;
  z-index: 1;
}

.logo {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 20%;
  width: 20%;
  background: url('https://i.vgy.me/7FcUbx.jpg') center center / cover;
  z-index: 10;
  transform: translate(-50%, -50%);
}

@keyframes animate {
  0% {
    background-position: 0px;
  }
  100% {
    background-position: 1063px;
  }
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title> Clouds </title>

  <link rel="stylesheet" href="clouds.css">
</head>

<body>
  <div class="container">
    <div class="clouds"></div>
    <div class="logo"></div>
  </div>
  
</body>

关于html - 在 css 动画之上叠加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56121071/

相关文章:

html - 资源被解释为样式表但在控制台中以 MIME 类型文本/html 错误传输

html - CSS。链接不适用于输入 :focus

css - 动画:延迟后填充

html - 如何在页脚上设置背景图像

HTML 到 PDF 内容溢出到下一页

html - HTML5视频标签youtube

JQuery 单击事件无法正常工作

html - 带背景图像的 div 周围的空间

html - 如何居中这个翻转卡片示例?

html - html 和正文标签的边距、填充、高度和宽度