css3實現的可伸縮圓角導航選單

antzone發表於2017-03-26

分享一段程式碼例項,它實現了滑鼠懸浮可伸縮導航選單效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
body {
  background-color: #EAEAEA;
}
#nav {
  margin-top: 100px;
  margin-left: 50px;
  display: inline-block;
}
.item {
  float: right;
  padding: 6px;
  background-color: #EAEAEA;
  border-radius: 50px;
  margin-left: -40px;
  list-style: none;
}
.link {
  display: inline-block;
  background-color: #65ba99;
  width: 85px;
  height: 50px;
  border-radius: 50px;
  transition: .5s;
  text-align: center;
  text-decoration: none;
}
.link:hover {
  width: 130px;
  background-color: #77c2a5;
}
.link:hover span {
  opacity: 1;
}
ul li:last-child a {
  width: 60px;
  height: 60px;
  transform: scale(.84);
}
ul li:last-child {
  padding: 0;
}
#nav li:last-child a:hover {
  width: 60px;
  transform: scale(.95) !important;
  margin-right: 5px;
}
span {
  color: #DFDFDF;
  line-height: 50px;
  opacity: 0;
  transition: .5s;
}
</style>
</head>
<body>
  <ul id="nav">
    <li class="item"><a href="#" class="link"><span>螞蟻部落一</span></a></li>
    <li class="item"><a href="#" class="link"><span>螞蟻部落二</span></a></li>
    <li class="item"><a href="#" class="link"><span>螞蟻部落三</span></a></li>
    <li class="item"><a href="#" class="link"><span>螞蟻部落四</span></a></li>
    <li class="item"><a href="#" class="link"></a></li>
  </ul>
</body>
</html>

相關文章