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
You can go to the Ubuntu official website to down...
Recently, the business side reported that some us...
1. Introduction When the amount of data in the da...
Table of contents 1. Introduction to label statem...
This article shares the specific code of JavaScri...
describe: fuser can show which program is current...
1. After installing the Windows version of Docker...
Discuz! Forum has many configuration options in th...
The inline-block property value becomes very usef...
Preface Share two methods to monitor whether an e...
Preface I have been working on some front-end pro...
Table of contents Overview Single file components...
MySQL 5.7 version: Method 1: Use the SET PASSWORD...
1. Design source code Copy code The code is as fol...
This article shares the specific code for the WeC...