我有一个网页,其中我使用css淡入淡出动画在两个背景图像之间淡入淡出。现在,我需要在两个图像上方添加相同的内容(徽标和按钮)。但是,此内容仅对第一个图像可见,而对第二个图像不可见。 这是我的代码:
index.html
Error:Error in 1:nrow(x.2) : argument of length 0
Error:Calls: source ... <Anonymous> -> combined_rowdiffs -> rowdiff -> [ -> [.data.frame
style.css
background-image:url('../images/bg.png');
background-repeat:no-repeat;
background-size:contain;
background-position:center;
我已经筋疲力尽了。新增功能,请帮忙。
答案 0 :(得分:-1)
您要去的地方
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.img1 {
background: #e12;
position: absolute;
top: 0;
left: 0;
}
.img2:hover {
opacity: 0;
transition: .5s;
}
.img2 {
background: #312;
position: absolute;
top: 0;
left: 0;
transition: .5s;
}
.img1, .img2 { /* other - for demo */
color: white;
width: 100px;
height: 100px;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div class="img1"></div>
<div class="img2">Hello World</div>
</body>
</html>
将背景更改为图像,或者如果要使用img标签,请将每个img标签放在div中
答案 1 :(得分:-1)
这里有一个可行的示例,也许可以用它来修改您的代码;
@keyframes cf3FadeInOut {
0% {
opacity: 1;
}
45% {
opacity: 1;
}
55% {
opacity: 0;
}
100% {
opacity: 0;
}
}
.img-container,
.bg-img-1,
.bg-img-2,
.content {
height: 100vh;
width: 100vw;
}
.img-container {
position: relative;
}
.bg-img-1 {
background-image: url('https://images.pexels.com/photos/1509428/pexels-photo-1509428.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940');
background-size: cover;
position: absolute;
}
.bg-img-2 {
background-image: url('https://images.pexels.com/photos/886465/pexels-photo-886465.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940');
position: absolute;
background-size: cover;
animation-name: cf3FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 3s;
animation-direction: alternate;
}
.content {
background-color: rgba(0,0,0,0.5);
color: #fff;
position: absolute;
display: flex;
justify-content: center;
align-items: center;
}
<div class="img-container">
<div class="bg-img-1"></div>
<div class="bg-img-2"></div>
<div class="content">
<div>
hello <button>world</button>
</div>
</div>
<div>