我正在尝试在鼠标悬停时使标题出现在图像上,但它们都必须具有相同的类。我不知道我所问的是否可能,但我会考虑各种不同的解决方案。这是我目前的代码。
<div class="item"> <img class="Placeholderimg" src="placeholder.jpg"> <div class="hovershow1"> <div class="title"> Testing1 </div> </div> </a> </div> <div class="item"> <img class="Placeholderimg" src="placeholder.jpg"> <div class="hovershow2"> <div class="title"> Testing2 </div> </div>
这是我的CSS代码
.item{ height: 156px; width: 156px; } .Placeholderimg{ height: 156px; width: 156px; border-radius: 10px; } .hovershow1{ visibility: hidden; position: absolute; top:0; height: 156px; width:156px; background-color: rgba(40, 40, 40, 0.4); border-radius: 10px; } .item:hover .hovershow1{ visibility:visible; } .hovershow2{ visibility: hidden; position: absolute; top:0; height: 156px; width:156px; background-color: rgba(40, 40, 40, 0.4); border-radius: 10px; } .item:hover .hovershow2{ visibility:visible; }
P粉7096447002023-09-10 15:21:29
我只是不得不将位置更改为相对位置,这是我的代码
.item{ height: 156px; width: 156px; } .Placeholderimg{ height: 156px; width: 156px; border-radius: 10px; } .hovershow{ visibility: hidden; position: relative; height: 156px; width:156px; background-color: rgba(40, 40, 40, 0.4); border-radius: 10px; } .item:hover .hovershow{ visibility:visible; }