如何創建:圖像疊加標題
學習如何在鼠標懸停時創建圖像疊加標題。
圖像疊加標題
請將鼠標懸停在圖像上,即可查看疊加效果。

如何創建疊加圖像標題
第一步 - 添加 HTML:
<div class="container"> <img src="img_avatar.png" alt="Avatar" class="image"> <div class="overlay">My Name is John</div> </div>
第二步 - 添加 CSS:
* {box-sizing: border-box} /* 需要放置覆蓋層的容器。根據需要調整寬度 */ .container { position: relative; width: 50%; max-width: 300px; } /* 使圖像可響應 */ .image { display: block; width: 100%; height: auto; } /* 疊加效果 - 位于容器頂部和圖像上方 */ .overlay { position: absolute; bottom: 0; background: rgb(0, 0, 0); background: rgba(0, 0, 0, 0.5); /* Black see-through */ color: #f1f1f1; width: 100%; transition: .5s ease; opacity:0; color: white; font-size: 20px; padding: 20px; text-align: center; } /* 當您將鼠標懸停在容器上時,淡入疊加標題 */ .container:hover .overlay { opacity: 1; }
相關頁面
教程:CSS 圖像
教程:如何創建圖像疊加懸停效果