This article introduces an example of using HTML+CSS to implement a secondary menu bar when the mouse is moved. The details are as follows: First, the effect picture: 1. The mouse is not on it 2. Place the mouse on the first-level menu to expand the second-level menu 3. Place the mouse on the secondary menu Code: <html> <head> <title>Secondary menu test</title> <meta charset="utf-8"> <style type="text/css"> /*To center the menu*/ body { padding-top:100px; text-align:center; } /* -------------Menu css code----------begin---------- */ .menuDiv { border: 2px solid #aac; overflow: hidden; display:inline-block; } /* Remove the underline of the a tag*/ .menuDiv a { text-decoration: none; } /* Set the style of ul and li */ .menuDiv ul , .menuDiv li { list-style: none; margin: 0; padding: 0; float: left; } /* Set the secondary menu to absolute positioning and hide it*/ .menuDiv > ul > li > ul { position: absolute; display: none; } /* Set the style of the li of the secondary menu */ .menuDiv > ul > li > ul > li { float: none; } /* Put the mouse on the first-level menu to display the second-level menu*/ .menuDiv > ul > li:hover ul { display: block; } /* First level menu */ .menuDiv > ul > li > a { width: 120px; line-height: 40px; color: black; background-color: #cfe; text-align: center; border-left: 1px solid #bbf; display: block; } /* In the first level menu, do not set the left border */ .menuDiv > ul > li:first-child > a { border-left: none; } /* In the first level menu, the style of the mouse on it*/ .menuDiv > ul > li > a:hover { color: #f0f; background-color: #bcf; } /* Secondary menu */ .menuDiv > ul > li > ul > li > a { width: 120px; line-height: 36px; color: #456; background-color: #eff; text-align: center; border: 1px solid #ccc; border-top: none; display: block; } /* In the secondary menu, the first one sets the top border*/ .menuDiv > ul > li > ul > li:first-child > a { border-top: 1px solid #ccc; } /* In the secondary menu, the style of the mouse on it*/ .menuDiv > ul > li > ul > li > a:hover { color: #a4f; background-color: #cdf; } /* -------------Menu css code----------end---------- */ </style> </head> <body> <!-- -------Menu html code---------begin------- --> <div class="menuDiv"> <ul> <li> <a href="#">Menu 1</a> <ul> <li><a href="#">Secondary Menu</a></li> <li><a href="#">Secondary Menu</a></li> <li><a href="#">Secondary Menu</a></li> </ul> </li> <li> <a href="#">Menu 2</a> <ul> <li><a href="#">Secondary Menu</a></li> <li><a href="#">Secondary Menu</a></li> </ul> </li> <li> <a href="#">Menu Three</a> <ul> <li><a href="#">Secondary Menu</a></li> <li><a href="#">Secondary Menu</a></li> <li><a href="#">Secondary Menu</a></li> <li><a href="#">Secondary Menu</a></li> <li><a href="#">Secondary Menu</a></li> </ul> </li> <li> <a href="#">Menu 4</a> </li> <li> <a href="#">Menu Five</a> <ul> <li><a href="#">Secondary Menu</a></li> <li><a href="#">Secondary Menu</a></li> <li><a href="#">Secondary Menu</a></li> </ul> </li> </ul> </div> <!-- -------Menu html code---------end------- --> </body> </html> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: How to use nginx as a proxy cache
>>: CSS imitates Apple's smooth switch button effect
introduction In recent years, the call for TypeSc...
Table of contents Preface 1. Routing lazy loading...
After pressing Enter on the webpage, the form is a...
In the forum, I saw netizen jeanjean20 mentioned h...
Table of contents Preface Array.isArray construct...
Table of contents ReactRouterV6 Changes 1. <Sw...
Set the width of the body to the width of the wind...
The previous three articles introduced common bac...
Table of contents 1. Easy to use 2. Using generic...
Table of contents 1. Pull the image 1.1 Pull the ...
Preface: In MySQL, views are probably one of the ...
Introduction The default source of Ubuntu is not ...
This article shares the specific code of jQuery t...
Table of contents App Update Process Rough flow c...