Detailed explanation of the steps to implement a large drop-down menu with CSS

php中世界最好的语言
Release: 2018-05-07 17:38:52
Original
1414 people have browsed it

This time I will bring you a detailed explanation of the steps to implement a large drop-down menu with CSS. What are the precautions for implementing a large drop-down menu with CSS? The following is a practical case, let’s take a look.

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

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Detailed explanation of the steps to develop mpvue framework with Vue.js

jquery fullpage plug-in to add header and tail copyright Related

The above is the detailed content of Detailed explanation of the steps to implement a large drop-down menu with 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!