小编给大家分享一下纯CSS怎么实现大型下拉菜单,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!HTML结构该大型菜单的html结构如下:<nav>&nb
小编给大家分享一下纯CSS怎么实现大型下拉菜单,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
HTML结构
该大型菜单的html结构如下:
<nav> <ul class="container ul-reset"> <li><a href='#'>Home</a></li> <li class='droppable'> <a href='#'>CateGory One</a> <div class='mega-menu'> <div class="container cf"> <ul class="ul-reset"> <h4>Heading 1</h4> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> </ul><!-- .ul-reset --> <ul class="ul-reset"> <h4>Heading 2</h4> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> </ul><!-- .ul-reset --> <ul class="ul-reset"> <h4>Heading 3</h4> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> <li><a href='#'>Category One Sublink</a></li> </ul><!-- .ul-reset --> <ul class="ul-reset"> <h4>Heading 4</h4> <li><img src="Http://placehold.it/205x172"></li> </ul> </div><!-- .container --> </div><!-- .mega-menu --> </li><!-- .droppable --> <li class='droppable'> <a href='#'>Category Two</a> <div class='mega-menu'> <div class="container cf"> <ul class="ul-reset"> <h4>Heading 1</h4> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> </ul><!-- .ul-reset --> <ul class="ul-reset"> <h4>Heading 2</h4> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> </ul><!-- .ul-reset --> <ul class="ul-reset"> <h4>Heading 3</h4> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> </ul><!-- .ul-reset --> <ul class="ul-reset"> <h4>Heading 4</h4> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> <li><a href='#'>Category Two Sublink</a></li> </ul><!-- .ul-reset --> </div><!-- .container --> </div><!-- .mega-menu--> </li><!-- .droppable --> <li><a href='#'>Category Three</a></li> <li><a href='#'>Category Four</a></li> <li><a href='#'>Category Five</a></li> <li><a href='#'>Category Six</a></li> </ul><!-- .container .ul-reset --></nav>
CSS
为该大型菜单添加下面的CSS样式:
html {box-sizing: border-box;}*, *:before, *:after {box-sizing: inherit; }body { background: url(../img/black-wood-small.jpg); color: #DDD; font-family: "Open Sans", sans-serif; font-size: 14px; line-height: 1; margin: 0; padding: 0; text-align: center;}a {text-decoration: none;}h2 { font-size: 40px; font-weight: 700; margin-bottom: 20px; margin-top: 20px;}h3 { font-size: 15px; font-weight: 600; margin-bottom: 30px; margin-top: 10px;}.container { margin: auto; width: 940px;}.ul-reset { padding-left: 0; margin-top: 0; margin-bottom: 0; list-style: none;}nav { background: #424242; font-size: 0; position: relative;}nav > ul > li { display: inline-block; font-size: 14px; padding: 0 15px; position: relative;}nav > ul > li:first-child {padding-left: 0;}nav > ul > li:last-child {padding-right: 0;}nav > ul > li > a { color: #fff; display: block; position: relative; padding: 20px 0; border-bottom: 3px solid transparent;}nav > ul > li:hover > a { color: #69aae0; border-bottom: 3px solid #69aae0;}.mega-menu { background: #f0f0f0; display: none; left: 0; position: absolute; text-align: left; width: 100%;}.mega-menu h4 {color: #444;}.mega-menu ul { float: left; margin-bottom: 20px; margin-right: 40px; width: 205px;}.mega-menu ul:last-child {margin-right: 0;}.mega-menu a { border-bottom: 1px solid #ddd; color: #4ea3D8; display: block; padding: 10px 0;}.mega-menu a:hover {color: #2d6a91;}.droppable {position: static;}.droppable > a:after { content: "\f107"; font-family: FontAwesome; font-size: 12px; padding-left: 6px; position: relative; top: -1px;}.droppable:hover .mega-menu {display: block;}.cf:before,.cf:after { content: " "; display: table; }.cf:after {clear: both;}
以上是“纯CSS怎么实现大型下拉菜单”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网精选频道!
--结束END--
本文标题: 纯CSS怎么实现大型下拉菜单
本文链接: https://lsjlt.com/news/253134.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0