gpt4 book ai didi

html - 卡片覆盖仅在图像上滑动?

转载 作者:太空宇宙 更新时间:2023-11-04 15:46:50 27 4
gpt4 key购买 nike

我有一个使用 Bootstrap 4 的卡片库部分,希望用户将鼠标悬停在每张卡片上以进行覆盖幻灯片/或淡入但仅覆盖图像。截至目前,它在整张卡片上滑动。

我似乎无法让它正好适合卡片。我知道现在我已经将 widthheight 设置为 100%,它覆盖了整张卡片,但是当我移除覆盖层时,覆盖层很小并且滑过两者之间的间隙图像和边框。有什么想法吗?

其中一张卡片的 HTML:

<div class="card mt-6">
<div class="px-3">
<div class="card-overlay">
<h1 class="card-overlay-heading">Meet Brian!</h1>
<script src="https://fast.wistia.com/embed/medias/.jsonp" async></script>
<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>
<span class="wistia_embed wistia_async_ popover=true popoverContent=link" style="display:inline;position:relative">
<a href="#"><i class="fas fa-play"></i></a></span>
</div>
<img src="images/Lorraine.png" class="card-img" alt="">
</div>
<div class="card-body">
<h6 class="card-title mb-0 text-uppercase">Mark D</h6>
<p class="card-text mb-3 text-green fw-bold">Web</p>
</div>
</div>

CSS:

.card {
position: relative;
overflow: hidden;
}

.card:hover .card-overlay {
left: 0;
}

.card-overlay {
position: absolute;
top: 0;
left: -100%;
background-color: rgba(85, 211, 150, 0.6);
color: #fff;
height: 100%;
width: 100%;
z-index: 10;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
transition: left .7s;
}

最佳答案

position: relative 添加到图像的 wrapper (现在 overlayrelative card 这就是为什么你把它放在整张卡片上的原因) - 请参见下面的演示:

.card {
position: relative;
overflow: hidden;
}
.card > div { /* ADDED THIS */
position: relative;
}

.card:hover .card-overlay {
left: 0;
}

.card-overlay {
position: absolute;
top: 0;
left: -100%;
background-color: rgba(85, 211, 150, 0.6);
color: #fff;
height: 100%;
width: 100%;
z-index: 10;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
transition: left .7s;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

<div class="container">
<div class="card mt-6" style="width:300px">
<div class="px-3">
<div class="card-overlay">
<h1 class="card-overlay-heading">Meet Brian!</h1>
<span class="wistia_embed wistia_async_ popover=true popoverContent=link" style="display:inline;position:relative">
<a href="#"><i class="fas fa-play"></i></a></span>
</div>
<img src="https://via.placeholder.com/50" class="card-img" alt="">
</div>
<div class="card-body">
<h6 class="card-title mb-0 text-uppercase">Mark D</h6>
<p class="card-text mb-3 text-green fw-bold">Web</p>
</div>
</div>
</div>

关于html - 卡片覆盖仅在图像上滑动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54789294/

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