CSS3中如何实现鼠标悬停在菜单上时-出现相应的动画效果呢?


摘要:
下文讲述使用css代码为一个菜单制作一个鼠标悬停的效果的方法分享,如下所示:

下午将通过示例的方式讲述其方法,如下所示:

  实现思路:
      1.为菜单元素设置hover属性
	      设置其待放入菜单下元素的位置left
	  2.设置菜单下放入元素的transition属性
	      使其呈现出动画效果
 

例:
css3代码编写一个鼠标放入菜单上时出现动画效果的示例分析

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.maomao365.com/" />
<title>猫猫小屋</title>
<style type="text/css">
* {
  margin: 0;
  padding: 0;
}
html {
  font-size: 62.5%;
}
a, a:hover, a:focus {
  text-decoration: none;
}
ul, li {
  list-style: none;
}
body {
  font-family: "mircoft yahei";
  font-size: 14px;
  font-size: 1.4rem;
  line-height: 1;
}
.clearfix:after {
  display: block;
  content: '';
  clear: both;
}
.nav {
  text-align: center;
  margin: 8rem 0;
}
.wrapper {
  position: relative;
  display: inline-block;
  text-align: center;
}
.nav .wrapper:after {
  position: absolute;
  bottom: -0.2rem;
  display: block;
  content: '';
  width: 100%;
  height: 2px;
  background-color: #FF0132;
}
.nav a {
  float: left;
  color: #000;
  padding: 1.2rem 3.6rem;
  display: block;
  position: relative;
}
.nav a:hover {
  color: #FF0132;
}
.nav a:after {
  position: absolute;
  top: 3.6rem;
  left: 45%;
  display: block;
  content: '';
  width: 0.6rem;
  height: 0.6rem;
  background-color: #FF0132;
  border-radius: 100%;
}
.dot {
  display: block;
  position: absolute;
  top: 3.4rem;
  left: -12.5%;
  width: 0.9rem;
  height: 0.9rem;
  background-color: #FF0132;
  border-radius: 100%;
  opacity: 0;
  -webkit-transition: 0.6s ease-in-out;
  -moz-transition: 0.6s ease-in-out;
  -o-transition: 0.6s ease-in-out;
  transition: 0.6s ease-in-out;
}
.nav a:first-child:hover ~ .dot {
  left: 9%;
}
.nav a:nth-child(2):hover ~ .dot {
  left: 31.5%;
}
.nav a:nth-child(3):hover ~ .dot {
  left: 57.5%;
}
.nav a:nth-child(4):hover ~ .dot {
  left: 85.5%;
}
.nav a:hover ~ .dot {
  opacity: 1;
}
</style>
</head>
<body>
  <nav class="nav">
    <div class="wrapper clearfix">
      <a href="">菜单一</a>
      <a href="">菜单二</a>
      <a href="">菜单三</a>
      <a href="">菜单四</a>
      <i class="dot"></i>
    </div>
  </nav>
</body>
</html>
css3为菜单设置动画的示例分享

css3为菜单设置动画的示例分享