css滑鼠懸浮小圖彈出大圖效果

螞蟻小編發表於2017-04-09

本章節分享一段程式碼例項,它實現了滑鼠懸浮小圖彈出大圖效果。

非常的簡單,程式碼如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
* {
  margin: 0;
  padding: 0;
}
a {
  text-decoration: none;
}
body {
  width: 620px;
  margin: 0 auto;
  text-align: center;
  padding-top: 30px;
}
ul {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px dashed #c8c8c8;
}
li {
  display: inline-block;
  position: relative;
  list-style: none;
  border: 1px solid #ccc;
  border-color: #ddd #bbb #aaa #ccc;
}
a > img:first-child {
  width: 105px;
  height: 80px;
  padding: 2px;
  border: 5px solid #ddd;
}
.previewImg {
  display: none;
  position: absolute;
  background-color: #ddd;
  width: 200px;
  height: 150px;
  top: -25px;
  left: -43px;
  z-index: 10;
}
a:hover .previewImg {
  display: block;
  border: 1px solid #333;
  padding: 2px;
}
</style>
</head>
<body>
<ul>
  <li>
    <a href="#">
      <img src="demo/CSS/img/photo01.jpg" alt="螞蟻部落" />
      <img src="demo/CSS/img/photo01.jpg" alt="softwhy.com" class="previewImg" />
    </a>
  </li>
</ul>
</body>
</html>

相關文章