我试图用鼠标指针悬停在所有三张卡上以显示文本,但是即使我已经放了三张卡,它也只在左侧的第一张卡上显示文本,而在其他两张卡上不显示文本在所有3个div中不会显示的lorem ipsom文本。
我已经在网上寻找解决方案,但是找不到任何解决方案。看来我可能必须添加一个JavaScript循环才能对其进行遍历,但是我无法弄清楚该如何做。
<div class="wrapper">
<div class="card" id='card'>
<div class="orangeCover">
<p id="hidden" class='easein'>Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Ipsa, eaque.
</p>
</div>
</div>
<div class="card" id='card'>
<div class="orangeCover">
<p id="hidden" class='easein'>Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Ipsa, eaque.
</p>
</div>
</div>
<div class="card" id='card'>
<div class="orangeCover">
<p id="hidden" class='easein'>Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Ipsa, eaque.
</p>
</div>
</div>
</div>
html,
body {
margin: 0;
}
.wrapper {
width: 100vw;
height: 100vh;
overflow: hidden;
display: grid;
grid-column-gap: 20px;
grid-row-gap: 20px;
grid-template-columns: auto auto auto auto;
}
.orangeCover {
width: 250px;
height: 250px;
position: absolute;
}
.orangeCover:hover {
background-color: orangered;
transition: ease-in 0.5s;
}
.card {
border: 2px orangered solid;
width: 250px;
height: 250px;
margin-left: 100px;
margin-top: 100px;
background-image: url("http://source.unsplash.com/random/250x250");
}
#hidden {
visibility: hidden;
}
.reveal {
margin-left: 20px;
color: white;
font-size: 1.5rem;
}
let text = document.querySelector("#hidden"), i;
let overlay = document.querySelector(".card");
let hiddenOverlay = document.querySelector(".card");
overlay.addEventListener("mouseover", newOverlay);
hiddenOverlay.addEventListener("mouseleave", hidden);
function newOverlay() {
text.style.visibility = "visible";
text.className = "reveal";
}
function hidden() {
text.style.visibility = "hidden";
}