我有一个flexbox,其中包含3个图片,我已经将它们设置为相同的宽度和高度。现在我想添加一个文本,使其位于每个图像的中心。我的最终目标是添加悬停效果,以便在悬停时显示文本。
通过其他一些教程,我发现需要将段落添加到另一个div中。但是,我无法将文本容器“重叠”在相应的图像上方。有没有什么提示或技巧可以最好地实现这一点呢?
.flexbox {
position: relative;
display: flex;
flex-direction: row;
width: 100%;
max-height: 80vh;
}
.container {
width: 34%;
max-height: 70vh;
display: block;
text-align: center;
}
.image-category {
width: 100%;
opacity: 0.6;
max-height: inherit;
overflow: hidden;
}
<div class="flexbox" id="flex">
<div class="container" id="box1">
<img class="image-category" id="product3" src="https://img.fotocommunity.com/landschaft-geht-auch-hochkant-0d77b881-6996-4001-bbd4-74ec6b27f14e.jpg?height=1080">
<div class="image-description">
<p class="description">Example 1</p>
</div>
</div>
<div class="container" id="box2">
<img class="image-category" id="product2" src="https://img.fotocommunity.com/landschaft-geht-auch-hochkant-0d77b881-6996-4001-bbd4-74ec6b27f14e.jpg?height=1080">
<div class="image-description">
<p class="description">Example 2</p>
</div>
</div>
<div class="container" id="box3">
<img class="image-category" id="product3" src="https://img.fotocommunity.com/landschaft-geht-auch-hochkant-0d77b881-6996-4001-bbd4-74ec6b27f14e.jpg?height=1080">
<div class="image-description">
<p class="description">Example 3</p>
</div>
</div>