CSS3的一个简单导航栏实现
程序员文章站
2022-12-01 08:53:00
这篇文章主要介绍了CSS3的一个简单导航栏实现,无需用到JavaScript,文章最后附有demo,需要的朋友可以参考下... 15-08-03...
上面是一个效果图,代码在下面:
html
xml/html code复制内容到剪贴板
- <nav>
- <ul class="nav-ul">
- <li>
- <a href="/">首页</a>
- </li>
- <li>
- <a href="/category/frontend">web前端</a>
- <ul>
- <li class="nav-effect-1">
- <a href="/category/frontend/javascript">javascript</a>
- </li>
- <li class="nav-effect-2">
- <a href="/category/frontend/jq">jquery</a>
- </li>
- <li class="nav-effect-3">
- <a href="/category/frontend/style">css</a>
- </li>
- <li class="nav-effect-4">
- <a href="/category/frontend/html">html</a>
- </li>
- </ul>
- </li>
- <li>
- <a href="/category/end">后端</a>
- <ul>
- <li class="nav-effect-1">
- <a href="/category/end/python-end">python</a>
- </li>
- <li class="nav-effect-2">
- <a href="category/end/php">php</a>
- </li>
- </ul>
- </li>
- <li>
- <a href="/category/trivial">琐碎杂类</a>
- <ul>
- <li class="nav-effect-1">
- <a href="/category/trivial/linux">linux</a>
- </li>
- <li class="nav-effect-2">
- <a href="/category/trivial/ajax">ajax</a>
- </li>
- </ul>
- </li>
- <li>
- <a href="/category/life">我的生活</a>
- <ul>
- <li class="nav-effect-1">
- <a href="/category/life/college">college</a>
- </li>
- <li class="nav-effect-2">
- <a href="/category/life/review">review</a>
- </li>
- <li class="nav-effect-3">
- <a href="/category/life/sentiment">sentiment</a>
- </li>
- </ul>
- </li>
- <li>
- <a href="#">关于我</a>
- <ul>
- <li class="nav-effect-1">
- <a href="/contribute">友情链接</a>
- </li>
- <li class="nav-effect-2">
- <a href="/message">留言板</a>
- </li>
- </ul>
- </li>
- </ul>
- </nav>
css:
css code复制内容到剪贴板
- *{
- margin:0 auto;
- }
- body{
- background-color: #eeeeee;
- font-family: microsoft yahei,arial,sans-serif;
- }
- nav{
- width: 100%;
- background-color: #455552;
- position: relative;
- width: 650px;
- margin-top: 100px;
- }
- .nav-ul{
- list-style: none;
- }
- .nav-ul>li{
- display: inline-block;
- position: relative;
- }
- .nav-ul a{
- text-decoration: none;
- color: #fff;
- display: inline-block;
- padding: 10px 20px;
- }
- .nav-ul a:hover{
- background-color: #1abc9c;
- }
- .nav-ul a:hover+ul li{
- opacity:1;
- -webkit-transform: rotatey(0deg);
- transform: rotatey(0deg);
- }
- .nav-ul a+ul{
- list-style: none;
- position: absolute;
- transition: opacity 0.5s;
- -webkit-perspective: 800;
- -webkit-transform-style: preserve-3d;
- }
- .nav-ul a+ul:hover li{
- opacity: 1;
- -webkit-transform: rotatey(0deg);
- transform: rotatey(0deg);
- }
- .nav-ul a+ul li{
- position: relative;
- left: -40px;
- opacity: 0;
- width: 150px;
- transition: transform 1.5s,opacity 0.8s;
- }
- .nav-ul a+ul a{
- display: inline-block;
- width: 75%;
- background-color: rgba(26,188, 156, 0.75);
- }
- .nav-effect-1{
- transform: rotatey(90deg) translatex(10px);
- }
- .nav-effect-2{
- transform: rotatey(120deg) translatex(20px);
- }
- .nav-effect-3{
- transform: rotatey(150deg) translatex(30px);
- }
- .nav-effect-4{
- transform: rotatey(180deg) translatex(40px);
- }
- .nav-ul a+ul a:hover{
- background-color: rgba(69,85, 82, 0.75);
- }
查看demo:
下一篇: 肠胃炎的八大饮食禁忌 肠胃炎的饮食原则