How to implement a large drop-down menu using CSS

不言
Release: 2018-06-21 17:03:28
Original
1758 people have browsed it

Drop-down menus can be used in many web pages. This article mainly introduces the relevant information about the sample code of large drop-down menus implemented in pure CSS. The content is quite good. I will share it with you now and give it as a reference. .

This is a large drop-down menu implemented in pure CSS. This large menu is made using HTML and pure CSS code, without any js code, and does not rely on any third-party plug-ins. Suitable for large websites with many column categories.

HTML structure

The HTML structure of the mega menu is as follows:

<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>
Copy after login

CSS

This is Add the following CSS style to the large menu:

/* #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;}
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to use CSS3 to implement waterfall flow layout

Implementation of CSS3 and HTML5 web page loading progress bar

The above is the detailed content of How to implement a large drop-down menu using CSS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template