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
1. Introduction Whether the creation time of a fi...
Docker Learning https://www.cnblogs.com/poloyy/p/...
There are many special symbols used in mathematic...
Table of contents Preface 1. What is scalability?...
WeChat Mini Programs are becoming more and more p...
Table of contents 1. Introduction 2. Main text 2....
1. Cancel the blue color of the a tag when it is ...
Automatic backup of MySQL database using shell sc...
Introduction to Docker Docker is an open source c...
1: Download from mysql official website https://d...
Table of contents K8S Advanced Features Advanced ...
A joint index is also called a composite index. F...
This article shares the specific code for impleme...
1. Create a docker network card [root@i ~]# brctl...
I'm building Nginx recently, but I can't ...