查看現有答案以及其他在線教程後,我仍然無法弄清懸停時如何在圖像上放置文本。這裏是形象會是什麼樣當光標懸停在圖像上類似的例子:使用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