Introduction: It’s still the same. Without further ado, let’s go straight to the renderings. 1. A button, before it is clicked (on a mobile phone) or when the mouse is not pointing (on a PC) 2. After clicking or pointing the mouse. The drop-down menu can be displayed, and its implementation principle is also very simple. You only need to remember one point: hover, this attribute. Let's jump right into the code and explain it later. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <style> li{ list-style: none; height: 28px; } #menu{ display: inline-block; } #menu #list { max-height: 0; transition: max-height 0.25s ease-out; overflow: hidden; background: #f5f4f4; width: 80px; margin: 0; padding: 0; text-align: center; } #menu:hover #list { max-height: 200px; transition: max-height 0.25s ease-in; width: 80px; margin: 0; padding: 0; } .button{ height: 32px; width: 80px; margin-top: 6px; border-radius: 4px; color: #fff; padding-left: 0; padding-right: 0; line-height: 32px; background: #E33E33; text-align: center; } </style> </head> <body> <div id="menu"> <div class="button">More information</div> <ul id="list"> <li>Personal Center</li> <li>My Blog</li> <li>Settings</li> <li>Log out</li> <li>Log out</li> </ul> </div> </body> </html> You just need to set a div and then set it to two states, one without :hover and one with :hover. And when there is no :hover, just set the menu to be hidden (overflow: hidden;), and the rest of the code is a simple box model. Now let’s talk about :hover. What is this thing? It is a CSS selector that is used to select the element on which the mouse pointer floats. So when the mouse is hovered or clicked on the mobile phone, this attribute will be triggered, and the drop-down menu will be displayed. At the same time, we added the transition attribute to make the drop-down menu have a gradient effect, making it feel more like it is being pulled down. So isn’t the CSS selector magical? If used well, you don’t have to write a lot of JS code. I will make a column about CSS selectors in the future, and then introduce all CSS selectors in a systematic way. Summarize This concludes this article about using pure CSS to create a sample code for a drop-down menu function. For more relevant CSS drop-down menu content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope that everyone will support 123WORDPRESS.COM in the future! |
<<: Semanticization of HTML tags (including H5)
>>: In-depth understanding of Vue's method of generating QR codes using vue-qr
question Nginx takes $remote_addr as the real IP ...
Table of contents Preface Common methods 1. Modif...
Preface In front-end programming, we often use th...
I recently bought the cheapest Tencent cloud serv...
Preface As we all know, by default, the MySQL ins...
echarts word cloud is an extension of echarts htt...
Preface When I was studying the front end before,...
Documentation: https://github.com/hilongjw/vue-la...
What is em? em refers to the font height, and the ...
Because I wrote the word transition incorrectly i...
1. Software Download MySQL download and installat...
Table of contents Preface 1. Routing lazy loading...
Table of contents Immediately execute function fo...
This article shares the specific code of NodeJS t...
background: Because the server deployed the flask...