css滑鼠懸浮tips效果程式碼例項

antzone發表於2017-04-11

分享一段程式碼例項,它利用css實現了滑鼠懸浮彈出tips效果。

更多特效可以查閱特效板塊滑鼠tips資訊分類。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
div {
  position: relative;
  width: 120px;
  line-height: 38px;
  margin: 100px auto;
  color: #333;
  text-align: center;
  font-size: 24px;
  cursor: pointer;
}
 
div:hover::before {
  content: attr(data-msg);
  position: absolute;
  top: -50px;
  left: 10px;
  padding: 2px 6px;
  display: inline-block;
  color: #333;
  border: 1px solid #333;
  border-radius: 5px;
  font-size: 14px;
}
 
div:hover::after {
  content: "";
  border-top: 5px solid #333;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  position: absolute;
  top: -6px;
  left: 60px;
}
</style>
</head>
<body>
<div data-msg="www.softwhy.com">滑鼠懸浮</div>
</body>
</html>

上面的程式碼實現了我們的要求,程式碼比較簡單,更多內容可以參閱相關閱讀。

相關閱讀:

(1).content可以參閱css content一章節。

(2).border-radius可以參閱CSS3 border-radius圓角一章節。

(3).::before可以參閱CSS E:before/E::before一章節。

相關文章