滑鼠懸浮連結動畫高亮效果

antzone發表於2018-07-17

分享一段程式碼例項,他事先了滑鼠懸浮連結,實現動畫高亮效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
div, p, a {
  margin: 0;
  padding: 0;
}
div {
  position: relative;
  z-index: 1;
  width: 800px;
  padding: 20px;
  border-radius: 20px;
  margin: 0 auto;
  background: #34495e;
  color: #b4b4b4;
  font-size: 20px;
  line-height: 26px;
  font-family: "Microsoft YaHei";
}
div a {
  position: relative;
  display: inline-block;
  outline: none;
  color: #e74c3c;
  vertical-align: bottom;
  text-decoration: none;
  white-space: nowrap;
}
div a:before {
  position: absolute;
  top: -3px;
  left: -3px;
  z-index: -1;
  width: 100%;
  height: 100%;
  box-sizing: content-box;
  content: '';
  padding: 3px;
  border-radius: 5px;
  background: #fff;
  opacity: 0;
  transition: transform 0.2s, opacity 0.2s;
  transform: scale(0);
}
div a:hover:before {
  opacity: 1;
  transform: scale(1);
}
</style>
</head>
<body>
  <div>
    本站的名稱是<a href="#">螞蟻部落</a>
  </div>
</body>
</html>

相關文章