• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

CSS文字覆盖图像悬停效果-CSS应用实例

css 程序员 8年前 (2017-12-03) 348次浏览 已收录 0个评论

 

<!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;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  width: 100%;
  opacity: 0;
  transition: .5s ease;
  background-color: #008CBA;
}

.container:hover .overlay {
  opacity: 1;
}

.text {
  color: white;
  font-size: 20px;
  position: absolute;
  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, Tihs is gaodaima site</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; top: 0; bottom: 0; left: 0; right: 0; height: 100%; width: 100%; opacity: 0; transition: .5s ease; background-color: #008CBA; } .container:hover .overlay { opacity: 1; } .text { color: white; font-size: 20px; position: absolute; 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&#8221; alt=”Avatar” class=”image”> <div class=”overlay”> <div class=”text”>Hello World, Tihs is gaodaima site</div> </div> </div> </body> </html>[/code]


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:CSS文字覆盖图像悬停效果-CSS应用实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址