gpt4 book ai didi

html - 悬停效果在同一时间和相同方式的两个类(class)

转载 作者:太空宇宙 更新时间:2023-11-04 13:16:20 24 4
gpt4 key购买 nike

我正在使用一个类来显示图像,我想通过两种方式添加悬停效果。第一个是如果我将鼠标悬停在图像上,过渡效果会显示标题和叠加图像。

HTML代码:

<div class="xoverlay x-simple"> <img class="x-img-main" src="img/best-img.jpg" />
<div class="xoverlay-box">
<div class="xoverlay-data"> <span class="x-circle x-white"> <a href="#"><i class="fa fa-facebook"></i></a> </span> <span class="x-circle x-white"> <a href="#"><i class="fa fa-twitter"></i></a> </span> <span class="x-circle x-white"> <a href="#"><i class="fa fa-user"></i></a> </span> <span>
<h2 class="hashTag">#hashTag</h2>
<p>It is a long established fact that a reader will be distracted by
the readable content of a page when looking at its layout</p>
<a class="x-more" href="#">More</a></span> </div>
</div>
</div>

和我的 CSS 代码:

.xoverlay {
position: relative;
overflow: hidden;
perspective: 300px;
-webkit-perspective: 300px;
-ms-perspective: 300px;
-o-perspective: 300px;
}
.x-simple {
width: 100%;
height: 300px;
}

.x-img-main {
width: 100%;
-webkit-transition: all .45s ease-in-out;
-moz-transition: all .45s ease-in-out;
-o-transition: all .45s ease-in-out;
-ms-transition: all .45s ease-in-out;
transition: all .45s ease-in-out;
}

.x-img-main:hover{
width:110%;
height:auto;
}

.x-simple:hover .xoverlay-box {
width: 100%;
height: 100%;
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
opacity: 1;
background: rgba(27,27,27,.7);
}

此代码为 JSFiddle .

最佳答案

您当前代码中的问题是,当您将鼠标悬停在 x-simple 元素上时,xoverlay-box 出现在 img 前面,并且悬停在 img 元素上'触发。

您不必在两个元素上应用悬停来实现对两个元素的效果。您可以在父元素上应用悬停并将其用于子元素。在 CSS 中只需替换

.x-img-main:hover{

.x-simple:hover .x-img-main{

已修改 JSFiddle

关于html - 悬停效果在同一时间和相同方式的两个类(class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25520464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com