css3水平滑動導航選單效果

admin發表於2017-02-22
本章節分享一段程式碼例項,它實現了水平滑動導航選單效果。

比較類似於橫向的時間軸,當然效果差距還是很大的。

再推薦一個類似的滑動導航選單,具體可以參閱css3滑鼠懸浮背景滑動導航選單一章節。

程式碼例項如下:

[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;
}
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.8s ease-in-out;
  -moz-transition: 0.8s ease-in-out;
  -o-transition: 0.8s ease-in-out;
  transition: 0.8s 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>

相關文章