【发布时间】:2018-11-28 20:03:01
【问题描述】:
我只想将叠加层添加到 bootstrap 4 figure-img。为此,我在 figure-img
下添加了带有 overlay 类的 div这是我的代码:
<div class="col-md-4">
<figure class="service text-center">
<img src="img/service1.jpg" class="figure-img img-fluid w-100" alt="Repair Request Service">
<div class="overlay"></div>
<figcaption class="figure-caption">
<h4>Repair Request Service</h4>
<p>We care about you and your vehicle. We want to make sure whether you see us for an auto repair or a scheduled maintenance, that we</p>
<a class="btn btn-primary" href="#">Read More</a>
</figcaption>
</figure>
</div>
CSS 是这样的:
.services .figure-img {
margin-bottom: 0;
position: relative;
}
.overlay {
position: absolute;
top: 0;
background: #f00;
height: 100%;
width: 100%;
opacity: 0;
display: none;
}
.service:hover .overlay {
display:block;
opacity: .3;
}
但叠加层占用了全宽,包括 col-md-4 左右填充。并显示如下:
如何解决这个问题,并在.figure-img中正确放置overlay?
【问题讨论】:
标签: html twitter-bootstrap css bootstrap-4