css实现鼠标悬停button文本改变

时间:2017-03-21
本文章向大家介绍如何使用css实现鼠标悬停在button上时,button的文本发生变化,这里主要使用到css的hover和before伪类,需要的朋友可以参考一下。

问题

我们想知道如何悬停更改按钮文字。

实现方法:

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='/js/lib/mootools-core-1.4.5-nocompat.js'></script>
<style type='text/css'>
button {<!-- http://www.manongjc.com 码农教程 -->
  width: 6em
}

button:hover span {
  display: none
}

button:hover:before {
  content: "Reply!"
}
</style>

</head>
<body>
  <button>
    <span>3 replies</span>
  </button>
</body>
</html>