<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>搞代码-CSS文字覆盖图像悬停从左至右效果-CSS应用实例(gaodaima.com)</title> <style> .container { position: relative; width: 50%; } .image { display: block; width: 100%; height: auto; } .overlay { position: absolute; bottom: 0; left: 0; right: 0; background-color: #008CBA; overflow: hidden; width: 0; height: 100%; transition: .5s ease; } .container:hover .overlay { width: 100%; } .text { white-space: nowrap; color: white; font-size: 20px; position: absolute; overflow: hidden; top: 50%; left: 50%; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); } </style> </head> <body> <h2>淡入效果 - 从左至右</h2> <p>鼠标移动到图片上查看效果</p> <div class="container"> <img src="http://img.gaodaima.com/paperimg_gaodaima_chengxuyuan.jpg" alt="Avatar" class="image"> <div class="overlay"> <div class="text">Hello World, gaodaima</div> </div> </div> </body> </html>
本文案例为大家展示了《CSS文字覆盖图像悬停从左至右效果》的代码,若要看代码效果请大家点击“运行代码”按钮。
[code]<!DOCTYPE html> <html> <head> <meta charset=”utf-8″> <title>搞代码-CSS文字覆盖图像悬停从左至右效果-CSS应用实例(gaodaima.com)</title> <style> .container { position: relative; width: 50%; } .image { display: block; width: 100%; height: auto; } .overlay { position: absolute; bottom: 0; left: 0; right: 0; background-color: #008CBA; overflow: hidden; width: 0; height: 100%; transition: .5s ease; } .container:hover .overlay { width: 100%; } .text { white-space: nowrap; color: white; font-size: 20px; position: absolute; overflow: hidden; top: 50%; left: 50%; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); } </style> </head> <body> <h2>淡入效果 – 从左至右</h2> <p>鼠标移动到图片上查看效果</p> <div class=”container”> <img src=”http://img.gaodaima.com/paperimg_gaodaima_chengxuyuan.jpg” alt=”Avatar” class=”image”> <div class=”overlay”> <div class=”text”>Hello World, gaodaima</div> </div> </div> </body> </html>[/code]