如何使用CSS实现的大型下拉菜单

不言
Lepaskan: 2018-06-21 17:03:28
asal
1752 orang telah melayarinya

下拉菜单在很多网页中都能应用到,这篇文章主要介绍了纯CSS实现的大型下拉菜单的示例代码的相关资料,内容挺不错的,现在分享给大家,也给大家做个参考。

这是一款纯CSS实现的大型下拉菜单。该大型菜单使用HTML和纯CSS代码制作,没有任何js代码,不依赖任意第三方插件。适合用于栏目分类较多的大型网站使用。

HTML结构

该大型菜单的HTML结构如下:

<nav>
  <ul class="container ul-reset">
    <li><a href=&#39;#&#39;>Home</a></li>
    <li class=&#39;droppable&#39;>
      <a href=&#39;#&#39;>Category One</a>
      <p class=&#39;mega-menu&#39;>
        <p class="container cf">
          <ul class="ul-reset">
            <h3>Heading 1</h3>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
          </ul><!-- .ul-reset -->
          <ul class="ul-reset">
            <h3>Heading 2</h3>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
          </ul><!-- .ul-reset -->
          <ul class="ul-reset">
            <h3>Heading 3</h3>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
            <li><a href=&#39;#&#39;>Category One Sublink</a></li>
          </ul><!-- .ul-reset -->
          <ul class="ul-reset">
            <h3>Heading 4</h3>
            <li><img src="http://placehold.it/205x172"></li>
          </ul>
        </p><!-- .container -->
      </p><!-- .mega-menu -->
    </li><!-- .droppable -->
    <li class=&#39;droppable&#39;>
      <a href=&#39;#&#39;>Category Two</a>
      <p class=&#39;mega-menu&#39;>
        <p class="container cf">
          <ul class="ul-reset">
            <h3>Heading 1</h3>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
          </ul><!-- .ul-reset -->
          <ul class="ul-reset">
            <h3>Heading 2</h3>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
          </ul><!-- .ul-reset -->
          <ul class="ul-reset">
            <h3>Heading 3</h3>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
          </ul><!-- .ul-reset -->
          <ul class="ul-reset">
            <h3>Heading 4</h3>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
            <li><a href=&#39;#&#39;>Category Two Sublink</a></li>
          </ul><!-- .ul-reset -->
        </p><!-- .container -->
      </p><!-- .mega-menu-->
    </li><!-- .droppable -->
    <li><a href=&#39;#&#39;>Category Three</a></li>
    <li><a href=&#39;#&#39;>Category Four</a></li>
    <li><a href=&#39;#&#39;>Category Five</a></li>
    <li><a href=&#39;#&#39;>Category Six</a></li>
  </ul><!-- .container .ul-reset -->
</nav>
Salin selepas log masuk

CSS

为该大型菜单添加下面的CSS样式:

/* #Resets
–––––––––––––––––––––––––––––––––––––––––––––––––– */
html {box-sizing: border-box;}
*, *:before, *:after {box-sizing: inherit;  }
/* #Universal and Default Styles
–––––––––––––––––––––––––––––––––––––––––––––––––– */
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;}
h1 {
  font-size: 40px;
    font-weight: 700;
  margin-bottom: 20px;
    margin-top: 20px;
}
h2 {
  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;
}
/* #Navigation Styles
–––––––––––––––––––––––––––––––––––––––––––––––––– */
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 Styles
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.mega-menu {
  background: #f0f0f0;
    display: none;
    left: 0;
    position: absolute;
    text-align: left;
    width: 100%;
}
.mega-menu h3 {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 Class Styles
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.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;}
/* #Browser Clearfix
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.cf:before,
.cf:after {
  content: " "; /* 1 */
   display: table; /* 2 */
}
.cf:after {clear: both;}
Salin selepas log masuk

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

如何使用CSS3实现瀑布流布局

CSS3和HTML5网页加载进度条的实现

Atas ialah kandungan terperinci 如何使用CSS实现的大型下拉菜单. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan