search
HomeWeb Front-endCSS TutorialCreate the most beautiful CSS multi-level drop-down horizontal navigation menu code sharing

The example in this article shares the pure CSS implementation of multi-level drop-down horizontal navigation menu code for your reference. The specific content is as follows

Let’s take a look at the renderings first:

Create the most beautiful CSS multi-level drop-down horizontal navigation menu code sharing

Implementation code:

CSS code:

<style type="text/css">   
/* for this demo only */  
#backgroundHolder { width:750px; height:500px; padding-top:10px; margin:0 auto; }   
/* ---------------------------------------------------------------------------- */  
/* default styling */  
.nav, .nav ul { list-style-type:none; margin:0; padding:0; }   
.nav a { text-decoration:none; }   
.nav { font-family: arial, sans-serif; font-size:12px; width:650px; margin:0 auto; }   
/* style the links */  
.nav a { background:url(ulmulti3/box.gif) no-repeat rightright center; }   
.nav a.top { background:url(ulmulti3/box.gif) no-repeat rightright top; }   
.nav a.top2 { background:url(ulmulti3/box2.gif) no-repeat rightright top; }   
.nav a.bottombottom { background:url(ulmulti3/box.gif) no-repeat rightright bottombottom; }   
.rightright ul ul a { background:url(ulmulti3/box3.gif) no-repeat rightright center; }   
.rightright ul ul a.top2 { background:url(ulmulti3/box3.gif) no-repeat rightright top; }   
.rightright ul ul a.bottombottom { background:url(ulmulti3/box3.gif) no-repeat rightright bottombottom; }   
/* style the <b> element so that is does not affect the size of the link */  
.nav a b { color:#fff; font-weight:normal; display:block; padding:5px 10px 5px 15px; }   
.nav .fly .main b { background: transparent url(ulmulti3/arrow.gif) no-repeat 117px 9px; }   
.nav .down b { background: transparent url(ulmulti3/arrow2.gif) no-repeat 115px 11px; }   
.nav .rightright ul b { text-align:rightright; }   
.nav .rightright ul ul b { padding: 5px 15px 5px 10px; }   
.nav .rightright ul .main b { background: transparent url(ulmulti3/arrow3.gif) no-repeat 15px 9px; text-align:rightright; }   
.nav .rightright ul ul .main b { background: transparent url(ulmulti3/arrow3.gif) no-repeat 5px 9px; text-align:rightright; }   
/* HEIGHT */  
.nav ul ul { top:-24px; } /* position the top of the flyout first sub menus */  
.nav ul ul ul { top:-25px; } /* position the top of the flyout second and third sub menus */  
.nav ul.two { top:-40px; } /* position the top of the flyout sub menus with previous text on two lines */  
/* WIDTH change this WITH CARE to suit your requirements */  
    
/*set the link width here*/  
.nav .drop, .nav a { width:130px; }   
.nav ul li { max-width:130px; } /* fix for IE8 */  
/* set the left flyout position here */  
.nav ul ul { left:130px; }   
/* set the right flyout position here */  
.nav li.rightright ul ul { left:auto; rightright:120px; }   
.nav li.rightright ul ul ul { left:auto; rightright:130px; }   
/* make this WIDTH - 1px */ /* or WIDTH - 0.063em if using em sizing */  
.nav a { margin-right:-129px; }   
/* ---------------------------------------------------------------------------- */  
    
/* DO NOT CHANGE ANYTHING BELOW */  
.nav li { float:left; } /* fixes IE bugs, and allows for clearing */  
.nav ul { float:left; position:relative; z-index:20; } /* necessary for float drop and to stack the <ul>s */  
.nav ul li { clear:left; } /* must clear the floated list item inside sublist */  
.nav a { position:relative; display:block; } /* needs to have a position, to be above the rest */  
.nav a.main { float:left; /* necessary for float drop */ margin-top:10000px; } /* bring the top level links back into view */  
.nav .drop, .nav .fly { margin-top:-10000px; } /* hide the sub links and their containers, opera has low upper limits */  
.nav ul { margin-bottom:-5000px; } /* avoid any interaction between the subs, can be any large size */  
/* The bit that does ALL the work to bring the sub menus into view */  
    
.nav a:hover, .nav a:focus, .nav a:active { margin-right:0; z-index:10; outline:0; }   
.nav a:hover b, .nav a:focus b, .nav a:active b { color:#000; cursor:pointer; } /* this is for keyboard tabbing color change */  
/* OPERA fix */  
.nav ul:hover, .nav ul ul:hover { clear:left; } /* to stop intermittent sub link :hover problems */  
    
/* ---------------------------------------------------------------------------- */  
</style>   
<!--[if lte IE 7]>   
<style type="text/css">   
/* bug fixes for IE7 and lower - DO NOT CHANGE */  
.nav .fly {width:99%;} /* make each flyout 99% of the prevous level */  
a:active {} /* requires a blank style for :active to stop it being buggy */  
</style>


html code:

    ##
    <body>  
    <p id="backgroundHolder">  
      <ul class="nav">  
        <li class="drop"><a class="main top" href="#url"><b>Home</b></a></li>  
        <li class="drop"><a class="main down top" href="#url"><b>Equipment</b></a>  
          <ul>  
            <li class="fly"><a class="main" href="#url"><b>Cameras</b></a>  
              <ul>  
                <li><a class="top2" href="#url"><b>Film Type</b></a></li>  
                <li><a href="#url"><b>Compact</b></a></li>  
                <li><a href="#url"><b>Polaroid</b></a></li>  
                <li><a href="#url"><b>Digital</b></a></li>  
                <li class="fly"><a class="main" href="#url"><b>Digital SLR</b></a>  
                  <ul>  
                    <li><a class="top2" href="#url"><b>Canon</b></a></li>  
                    <li><a href="#url"><b>Nikon</b></a></li>  
                    <li><a href="#url"><b>Panasonic</b></a></li>  
                    <li><a class="bottom" href="#url"><b>Kodak</b></a></li>  
                  </ul>  
                </li>  
                <li><a class="bottom" href="#url"><b>Second Hand</b></a></li>  
              </ul>  
            </li>  
            <li class="fly"><a class="main" href="#url"><b>Video Cameras & Accessories</b></a>  
              <ul class="two">  
                <li class="fly"><a class="main top2" href="#url"><b>Latest Models</b></a>  
                  <ul>  
                    <li><a class="top2" href="#url"><b>Nikon</b></a></li>  
                    <li><a href="#url"><b>Panasonic</b></a></li>  
                    <li><a href="#url"><b>Canon</b></a></li>  
                    <li><a href="#url"><b>Pentax</b></a></li>  
                    <li><a class="bottom" href="#url"><b>Minolta</b></a></li>  
                  </ul>  
                </li>  
                <li><a href="#url"><b>Special Offers</b></a></li>  
                <li><a class="bottom" href="#url"><b>Professional</b></a></li>  
              </ul>  
            </li>  
            <li class="fly"><a class="main" href="#url"><b>Lenses</b></a>  
              <ul>  
                <li class="fly"><a class="main top2" href="#url"><b>Digital</b></a>  
                  <ul>  
                    <li><a class="top2" href="#url"><b>Standard</b></a></li>  
                    <li><a href="#url"><b>Telephoto</b></a></li>  
                    <li><a href="#url"><b>Wide Angle</b></a></li>  
                    <li class="fly"><a class="main" href="#url"><b>Zoom</b></a>  
                      <ul>  
                        <li><a class="top2" href="#url"><b>Nikon</b></a></li>  
                        <li><a href="#url"><b>Pentax</b></a></li>  
                        <li><a href="#url"><b>Minolta</b></a></li>  
                        <li><a class="bottom" href="#url"><b>Panasonic</b></a></li>  
                      </ul>  
                    </li>  
                    <li class="fly"><a class="main" href="#url"><b>Zoom with Macro</b></a>  
                      <ul>  
                        <li><a class="top2" href="#url"><b>Panasonic</b></a></li>  
                        <li><a href="#url"><b>Minolta</b></a></li>  
                        <li><a href="#url"><b>Pentax</b></a></li>  
                        <li><a href="#url"><b>Canon</b></a></li>  
                        <li><a class="bottom" href="#url"><b>Nikon</b></a></li>  
                      </ul>  
                    </li>  
                    <li><a href="#url"><b>Fisheye</b></a></li>  
                    <li><a class="bottom" href="#url"><b>x2 converters</b></a></li>  
                  </ul>  
                </li>  
                <li class="fly"><a class="main" href="#url"><b>Standard SLR</b></a>  
                  <ul>  
                    <li><a class="top2" href="#url"><b>Canon</b></a></li>  
                    <li><a href="#url"><b>Nikon</b></a></li>  
                    <li><a href="#url"><b>Panasonic</b></a></li>  
                    <li><a href="#url"><b>Pentax</b></a></li>  
                    <li><a class="bottom" href="#url"><b>Minolta</b></a></li>  
                  </ul>  
                </li>  
                <li><a href="#url"><b>Cases</b></a></li>  
                <li class="fly"><a class="main" href="#url"><b>Large Format</b></a>  
                  <ul>  
                    <li><a class="top2" href="#url"><b>Hasselblad</b></a></li>  
                    <li><a href="#url"><b>Arca-Swiss</b></a></li>  
                    <li><a class="bottom" href="#url"><b>Leica</b></a></li>  
                  </ul>  
                </li>  
                <li><a href="#url"><b>Lens Hoods</b></a></li>  
                <li><a class="bottom" href="#url"><b>Lens Cleaners</b></a></li>  
              </ul>  
            </li>  
            <li><a href="#url"><b>Tripods</b></a></li>  
            <li><a href="#url"><b>Flashguns</b></a></li>  
            <li><a href="#url"><b>Accessories, filters & lens covers</b></a></li>  
            <li><a href="#url"><b>Special Offers</b></a></li>  
            <li><a class="bottom" href="#url"><b>Electronics</b></a></li>  
          </ul>  
        </li>  
        <li class="drop"><a class="main down top" href="#url"><b>Accessories</b></a>  
          <ul>  
            <li class="fly"><a class="main" href="#url"><b>Flashguns</b></a>  
              <ul>  
                <li class="fly"><a class="main top2" href="#url"><b>Digital Cameras</b></a>  
                  <ul>  
                    <li><a class="top2" href="#url"><b>Nikon</b></a></li>  
                    <li><a href="#url"><b>Canon</b></a></li>  
                    <li><a href="#url"><b>Panasonic</b></a></li>  
                    <li><a href="#url"><b>Pentax</b></a></li>  
                    <li><a class="bottom" href="#url"><b>Kodak</b></a></li>  
                  </ul>  
                </li>  
                <li><a href="#url"><b>Film Cameras</b></a></li>  
                <li><a href="#url"><b>Reflectors</b></a></li>  
                <li><a href="#url"><b>Stands</b></a></li>  
                <li><a href="#url"><b>Remote Control</b></a></li>  
                <li><a class="bottom" href="#url"><b>Batteries</b></a></li>  
              </ul>  
            </li>  
            <li class="fly"><a class="main" href="#url"><b>Filters</b></a>  
              <ul>  
                <li><a class="top2" href="#url"><b>Ultra Violet</b></a></li>  
                <li><a href="#url"><b>Lens protection</b></a></li>  
                <li><a href="#url"><b>Yellow</b></a></li>  
                <li><a href="#url"><b>Red</b></a></li>  
                <li><a href="#url"><b>Orange</b></a></li>  
                <li><a class="bottom" href="#url"><b>Blue</b></a></li>  
              </ul>  
            </li>  
            <li class="fly"><a class="main" href="#url"><b>Remote Control</b></a>  
              <ul>  
                <li><a class="top2" href="#url"><b>Canon</b></a></li>  
                <li><a href="#url"><b>Nikon</b></a></li>  
                <li><a class="bottom" href="#url"><b>Pentax</b></a></li>  
              </ul>  
            </li>  
            <li class="fly"><a class="main" href="#url"><b>Camera Cases</b></a>  
              <ul>  
                <li><a class="top2" href="#url"><b>Pentax</b></a></li>  
                <li><a href="#url"><b>Nikox</b></a></li>  
                <li><a href="#url"><b>Canon</b></a></li>  
                <li><a href="#url"><b>Pentax</b></a></li>  
                <li><a href="#url"><b>Kodak</b></a></li>  
                <li><a class="bottom" href="#url"><b>Minolta</b></a></li>  
              </ul>  
            </li>  
            <li><a class="bottom" href="#url"><b>Lens Brush</b></a></li>  
          </ul>  
        </li>  
        <li class="drop right"><a class="main down top" href="#url"><b>Outlets</b></a>  
          <ul>  
            <li><a href="#url"><b>Support</b></a></li>  
            <li><a href="#url"><b>Buying</b></a></li>  
            <li><a href="#url"><b>Photographers</b></a></li>  
            <li class="fly"><a class="main" href="#url"><b>Stockist</b></a>  
              <ul>  
                <li><a class="top2" href="#url"><b>Currys</b></a></li>  
                <li><a href="#url"><b>Dixons</b></a></li>  
                <li><a href="#url"><b>Jessops</b></a></li>  
                <li><a class="bottom" href="#url"><b>Staples</b></a></li>  
              </ul>  
            </li>  
            <li><a href="#5"><b>General</b></a></li>  
            <li class="fly"><a class="main bottom" href="#url"><b>Sales</b></a>  
              <ul>  
                <li><a class="top2" href="#url"><b>USA</b></a></li>  
                <li><a href="#url"><b>CANADA</b></a></li>  
                <li><a href="#url"><b>South America</b></a></li>  
                <li class="fly"><a class="main" href="#url"><b>Europe</b></a>  
                  <ul>  
                    <li><a class="top2" href="#url"><b>Britain</b></a></li>  
                    <li><a href="#url"><b>France</b></a></li>  
                    <li><a href="#url"><b>Germany</b></a></li>  
                    <li><a href="#url"><b>Spain</b></a></li>  
                    <li><a class="bottom" href="#url"><b>Italy</b></a></li>  
                  </ul>  
                </li>  
                <li><a href="#url"><b>Australia</b></a></li>  
                <li><a class="bottom" href="#url"><b>Asia</b></a></li>  
              </ul>  
            </li>  
          </ul>  
        </li>  
        <li class="drop"><a class="main top" href="#url"><b>Privacy Policy</b></a></li>  
      </ul>  
    </p>  
    <br>  
    <br>  
    <p align="center"> </p>  
      
    </body>
The above is the entire content of this article. I hope it will be helpful to everyone's learning. I also hope that everyone will support the PHP Chinese website.

The above is the detailed content of Create the most beautiful CSS multi-level drop-down horizontal navigation menu code sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
Using Pages CMS for Static Site Content ManagementUsing Pages CMS for Static Site Content ManagementMay 13, 2025 am 09:24 AM

I know, I know: there are a ton of content management system options available, and while I've tested several, none have really been the one, y'know? Weird pricing models, difficult customization, some even end up becoming a whole &

The Ultimate Guide to Linking CSS Files in HTMLThe Ultimate Guide to Linking CSS Files in HTMLMay 13, 2025 am 12:02 AM

Linking CSS files to HTML can be achieved by using elements in part of HTML. 1) Use tags to link local CSS files. 2) Multiple CSS files can be implemented by adding multiple tags. 3) External CSS files use absolute URL links, such as. 4) Ensure the correct use of file paths and CSS file loading order, and optimize performance can use CSS preprocessor to merge files.

CSS Flexbox vs Grid: a comprehensive reviewCSS Flexbox vs Grid: a comprehensive reviewMay 12, 2025 am 12:01 AM

Choosing Flexbox or Grid depends on the layout requirements: 1) Flexbox is suitable for one-dimensional layouts, such as navigation bar; 2) Grid is suitable for two-dimensional layouts, such as magazine layouts. The two can be used in the project to improve the layout effect.

How to Include CSS Files: Methods and Best PracticesHow to Include CSS Files: Methods and Best PracticesMay 11, 2025 am 12:02 AM

The best way to include CSS files is to use tags to introduce external CSS files in the HTML part. 1. Use tags to introduce external CSS files, such as. 2. For small adjustments, inline CSS can be used, but should be used with caution. 3. Large projects can use CSS preprocessors such as Sass or Less to import other CSS files through @import. 4. For performance, CSS files should be merged and CDN should be used, and compressed using tools such as CSSNano.

Flexbox vs Grid: should I learn them both?Flexbox vs Grid: should I learn them both?May 10, 2025 am 12:01 AM

Yes,youshouldlearnbothFlexboxandGrid.1)Flexboxisidealforone-dimensional,flexiblelayoutslikenavigationmenus.2)Gridexcelsintwo-dimensional,complexdesignssuchasmagazinelayouts.3)Combiningbothenhanceslayoutflexibilityandresponsiveness,allowingforstructur

Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)May 09, 2025 am 09:57 AM

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

CSS Animations: Is it hard to create them?CSS Animations: Is it hard to create them?May 09, 2025 am 12:03 AM

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframes CSS: The most used tricks@keyframes CSS: The most used tricksMay 08, 2025 am 12:13 AM

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools