As usual, today I will talk about a very practical CSS effect. When the mouse moves to the button, a drop-down menu will be automatically displayed. The effect is as follows: A very simple demo, the implementation steps are as follows: First, define a large div to wrap a button and a link group, and set the styles of the two elements under the div respectively. a connection group is hidden to set the hover effect of each part. Note here /* .dropdown's hover effect, acting on .dropdown-content*/ .dropdown:hover .dropdown-content { display: block; } Finally, attach the source code: <!DOCTYPE html> <html> <head> <title>Drop-down menu example</title> <meta charset="utf-8"> <style> body { margin: auto; } .dropbtn { background-color: #4CAF50; color: #fff; padding: 16px; font-size: 16px; border: none; cursor: pointer; } .dropdown { left: 47%; /* Declare it as relative positioning, the following sub-elements can refer to this element*/ position: relative; display: inline-block; } .dropdown-content { /* Hide the element */ display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; } .dropdown-content a:hover { background-color: #f1f1f1 } /* .dropdown's hover effect, acting on .dropdown-content*/ .dropdown:hover .dropdown-content { display: block; } .dropdown:hover .dropbtn { background-color: #3dc741; } </style> </head> <body> <h2 style="text-align: center;">Drop-down menu</h2> <p style="text-align: center;">Move the mouse over the button to open the drop-down menu</p> <div class="dropdown"> <button class="dropbtn">Drop-down menu</button> <div class="dropdown-content"> <a href="#" target="_block">Hello World 1</a> <a href="#" target="_block">Hello World 2</a> <a href="#" target="_block">Hello World 3</a> </div> </div> </body> </html> This is the end of this article about how to implement the Hover drop-down menu with CSS. For more relevant CSS Hover drop-down menu content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Three ways to create a gray effect on website images
>>: Difference between varchar and char types in MySQL
Copy code The code is as follows: <!-- Prevent...
1. Import the module and define a validation stat...
Seurat is a heavyweight R package for single-cell...
Table of contents 1. What is two-way data binding...
1 Get the installation resource package mysql-8.0...
1. Question: I have been doing insert operations ...
Sometimes you need to access some static resource...
Let's take a look at the dynamic splicing of ...
The following installations all use the ~/ direct...
1. The table tag is table, tr is row, td is cell, ...
Table of contents 1. Preparation Pull the redis i...
Table of contents Code cleaning "Frames"...
Table of contents How to deploy MySQL service usi...
margin:auto; + position: absolute; up, down, left...
History always repeats itself surprisingly well. ...