我有一个使用Bootstrap 4的卡片画廊部分,希望用户将鼠标悬停在每张卡片上以使其具有覆盖幻灯片/或淡入但只覆盖图像。截至目前,它在整个卡上滑动。
我似乎无法完全适合卡片。我知道到目前为止,width
和height
设置为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;
}
答案 0 :(得分:2)
将position: relative
添加到图像的包装器(现在overlay
是相对于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>