【发布时间】:2021-07-07 04:18:20
【问题描述】:
我目前正在尝试将 flexbox 用于我网站上的画廊...我遇到了一些问题,但这是唯一一个我无法弄清楚如何解决的问题。可能我可以对缺少的/可能做错的事情有不同的看法或方向。当我将鼠标悬停在图像上时,我的文本当前超出了它应该出现在图像上的位置。
我在这个 CodePen 中重现了我的问题: https://codepen.io/vinlune/pen/YzNeeyV
或者你可以在下面查看它——
html
<section class="galleryContainer">
<div class="galleryCol">
<div class="gallContent">
<a href="websitepage.html"><img src="https://media2.giphy.com/media/lnCvspqqhwzGMxmf8R/giphy.gif?cid=ecf05e47o1cwbqk74f1e9am33o60ojpf26lmdebbsuz8h5tw&rid=giphy.gif">
<div class="hoverText">
title <br /> content #1</div>
<p>cute corgi eating sushi</p></a>
</div>
<div class="gallContent">
<a href="websitepage.html"><img src="https://media3.giphy.com/media/SBiRK1eROiAHe0bg3A/giphy.gif">
<div class="hoverText">
title <br /> content #1</div>
<p>cute corgi drinking boba</p></a>
</div>
<div class="gallContent">
<a href="websitepage.html"><img src="https://media1.giphy.com/media/Kd5XdzdEhNqhYWe14S/giphy.gif">
<div class="hoverText">
title <br /> content #1</div>
<p>cute corgi eating cake</p></a>
</div>
</div>
</section>
css
a { /* */
text-decoration:none;
}
section.galleryContainer {
width: 92%;
height: auto;
padding: 0;
margin: 0 auto;
}
section.galleryContainer .galleryCol {
margin: 0 auto;
width: 100%;
display: flex;
justify-content: center;
flex-direction: row;
flex-wrap: wrap;
flex: 1 auto;
}
section.galleryContainer .galleryCol .gallContent {
width: 32%;
height: auto;
margin: auto;
padding: 4px;
background-color: #efefef;
}
section.galleryContainer .galleryCol .gallContent img{
width: 100%;
height: auto;
postion: relative;
display: block;
opacity: 1;
backface-visibility: hidden;
transition: 0.5s;
}
section.galleryContainer .galleryCol .gallContent:hover img {
background-color: #635ca8;
opacity: 0.2;
}
.galleryCol .gallContent .hoverText {
display: none;
text-align: center;
align-items: center;
transition: 0.5s;
}
.galleryCol .gallContent:hover .hoverText {
display: flex;
position: absolute;
flex-direction: row;
justify-content: center;
width: 100%;
height: 100%;
top: 25%;
opacity: 1;
z-index: 3;
}
感谢您的帮助!
【问题讨论】:
标签: html css image flexbox overlay