六边形 html 导航菜单,CSS实现多彩的六边形蜂窝菜单
时间: 2024-01-05 14:18:26 浏览: 114
html实现好看的多种风格导航菜单(源码)
5星 · 资源好评率100%
好的,以下是实现六边形蜂窝菜单的 HTML 和 CSS 代码,可以根据需要进行修改和优化:
HTML代码:
```
<div class="hexagon-menu">
<ul>
<li><a href="#">菜单1</a></li>
<li><a href="#">菜单2</a></li>
<li><a href="#">菜单3</a></li>
<li><a href="#">菜单4</a></li>
<li><a href="#">菜单5</a></li>
<li><a href="#">菜单6</a></li>
</ul>
</div>
```
CSS代码:
```
.hexagon-menu {
position: relative;
width: 450px;
margin: 0 auto;
text-align: center;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.hexagon-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.hexagon-menu li {
display: inline-block;
margin: 0 20px;
position: relative;
}
.hexagon-menu a {
display: block;
width: 100%;
height: 100%;
text-align: center;
text-decoration: none;
color: #fff;
font-size: 16px;
line-height: 60px;
}
.hexagon-menu li:before, .hexagon-menu li:after {
content: "";
display: block;
width: 0;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
left: -30px;
z-index: 1;
transition: all .3s ease-out;
}
.hexagon-menu li:before {
border-bottom: 52px solid #2c3e50;
top: -52px;
}
.hexagon-menu li:after {
border-top: 52px solid #2c3e50;
bottom: -52px;
}
.hexagon-menu li:hover:before, .hexagon-menu li:hover:after {
width: 60px;
transition: all .3s ease-out;
}
.hexagon-menu li:hover a {
background: #2c3e50;
}
.hexagon-menu li:nth-child(1):before, .hexagon-menu li:nth-child(1):after {
border-bottom-color: #e74c3c;
border-top-color: #e74c3c;
transition-delay: .1s;
}
.hexagon-menu li:nth-child(2):before, .hexagon-menu li:nth-child(2):after {
border-bottom-color: #1abc9c;
border-top-color: #1abc9c;
transition-delay: .2s;
}
.hexagon-menu li:nth-child(3):before, .hexagon-menu li:nth-child(3):after {
border-bottom-color: #3498db;
border-top-color: #3498db;
transition-delay: .3s;
}
.hexagon-menu li:nth-child(4):before, .hexagon-menu li:nth-child(4):after {
border-bottom-color: #9b59b6;
border-top-color: #9b59b6;
transition-delay: .4s;
}
.hexagon-menu li:nth-child(5):before, .hexagon-menu li:nth-child(5):after {
border-bottom-color: #f1c40f;
border-top-color: #f1c40f;
transition-delay: .5s;
}
.hexagon-menu li:nth-child(6):before, .hexagon-menu li:nth-child(6):after {
border-bottom-color: #e67e22;
border-top-color: #e67e22;
transition-delay: .6s;
}
```
这段代码可以实现一个六边形蜂窝菜单,其中每个菜单项的颜色和动画效果都可以通过修改 CSS 代码来实现。希望能对您有所帮助!
阅读全文