CSS3麵包屑導航選單

admin發表於2018-07-08

本章節分享一段程式碼例項,它實現了扁平化麵包屑導航選單程式碼例項。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
* {
  margin: 0;
  padding: 0;
}
body {
  text-align: center;
  background-color: #34495e;
}
ul {
  display: inline-block;
  margin-top: 200px;
}
ul li {
  list-style: none;
  float: left;
}
ul li a {
  text-decoration: none;
  background-color: #3498db;
  color: #FFF;
  display: block;
  height: 40px;
  line-height: 40px;
  padding: 0 20px 0 10px;
  position: relative;
  margin-right: 25px;
}
ul li:nth-child(even) a {
  background-color: #2980b9;
}
ul li:nth-child(even) a:before {
  border-color: #2980b9;
  border-left-color: transparent;
}
ul li:nth-child(even) a:after {
  border-left-color: #2980b9;
}
ul li:first-child a {
  padding-left: 20px;
  border-radius: 5px 0 0 5px;
}
ul li:last-child a {
  padding-right: 20px;
  border-radius: 0 5px 5px 0;
}
ul li a:before, ul li a:after {
  content: "";
  position: absolute;
  top: 0;
  border: 0 solid #3498db;
  border-width: 20px 10px;
  width: 0;
  height: 0;
}
ul li:first-child a:before {
  border: none;
}
ul li:last-child a:after {
  border: none;
}
ul li a:before {
  left: -20px;
  border-left-color: transparent;
}
ul li a:after {
  left: 100%;
  border-color: transparent;
  border-left-color: #3498db;
}
ul li a:hover {
  background-color: #1abc9c;
}
ul li a:hover:before {
  border-color: #1abc9c;
  border-left-color: transparent;
}
ul li a:hover:after {
  border-left-color: #1abc9c;
}
ul li a:active {
  background-color: #16a085;
}
ul li a:active:before {
  border-color: #16a085;
  border-left-color: transparent;
}
ul li a:active:after {
  border-left-color: #16a085;
}
</style>
</head>
<body>
<ul>
  <li><a href="#">首頁</a></li>
  <li><a href="#">螞蟻部落一</a></li>
  <li><a href="#">螞蟻部落二</a></li>
  <li><a href="#">螞蟻部落三</a></li>
  <li><a href="#">螞蟻部落四</a></li>
  <li><a href="#">螞蟻部落五</a></li>
  <li><a href="#">螞蟻部落六</a></li>
  <li><a href="#">softwhy.com</a></li>
</ul>
</body>
</html>

相關文章