查看现有答案以及其他在线教程后,我仍然无法弄清悬停时如何在图像上放置文本。这里是形象会是什么样当光标悬停在图像上类似的例子:使用HTML/CSS将文字定位在悬停的图像上
我当前的代码如下:
.project {
\t display: flex;
\t flex-direction: column;
\t justify-content: center;
\t align-items: center;
}
.project img {
\t margin-top: 3em;
\t width: 27em;
\t height: 25em;
\t position: relative;
}
.project img:hover .project p, .project img:hover .project h4 {
\t opacity: 1;
}
.project p, .project h4 {
\t background: rgba(0,0,0,0.5);
\t color: white;
\t height: 25em;
\t width: 27em;
\t position: absolute;
\t top: 0;
\t left: 0;
\t opacity: 0;
}
<div id="project_section">
\t \t <div class="container">
\t \t \t <div class="row">
\t \t \t \t <h2>PROJECTS</h2>
\t \t
\t \t \t \t <div class="col-sm-6 project">
\t \t \t \t \t <img src="https://www.planwallpaper.com/static/images/desktop-year-of-the-tiger-images-wallpaper.jpg" alt="">
\t \t \t \t \t <h4>Name</h4>
\t \t \t \t \t <p>Put some information here...</p>
\t \t \t \t </div>
\t \t \t
\t \t \t \t <div class="col-sm-6 project">
\t \t \t \t \t <img src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634_960_720.png" alt="">
\t \t \t \t \t <h4>Namep</h4>
\t \t \t \t \t <p>Put some information here...</p>
\t \t \t \t </div>
\t \t \t </div>
\t \t </div>
\t </div>
在当前状态下,当鼠标悬停在图像上时,文本完全不显示。我错过了什么?
悬停:) – Gerard
阿后面的文本应该变得可见。我会补充一点。 – sheriffderek
看起来不错!可以有背景图片而不是颜色吗?我尝试过用'background-image'替换'background'并使用你的解决方案,最终结果只是一个空白区域 – gcccpp