You can use CSS to create a drop-down menu after moving the mouse to display the effect.
You can use CSS to create a drop-down menu after moving the mouse to display the effect.
1. Implementation of the drop-down menu
The drop-down menu is displayed when you move the cursor to a specified element. The Code is as follows:
Simple drop-down menuClick here to show you the drop-down menu.
Drop-down menu 1
Drop-down menu 2
Instance resolution:
HTML section:
You can use any HTML element to open a drop-down menu, for example,.
Then, use
Element to create a container that contains the content of the drop-down menu and customizes the location where it will appear.
Finally, use
Element to wrap these elements, and use CSS to set the style of the drop-down content.
CSS section:
The. dropdown class uses position: relative, which places the content of the Set drop-down menu in the lower right corner of the drop-down button (using position: absolute.
The. dropdown-content class contains the actual drop-down menu. By default, it is hidden and displayed after you move the mouse over the specified element.
Note: In the preceding example, the container width in the drop-down menu is set to a minimum of PX, which can be customized as needed.
If you want the width of the drop-down menu to be the same as that of the drop-down button, you can set the width to 100%, and the overflow: auto attribute can be specified to scroll on a small screen.
: The hover selector is used to display the drop-down menu when you move the mouse over the drop-down button, and set the drop-down menu container to display: block;
2. Create a drop-down menu
Create a drop-down menu based on the above example and allow the user to select a project from the list.
Drop-down menu instance
Drop-down menu button
Drop-down menu item 1 drop-down menu item 2 drop-down menu item 3
In Chrome, the drop-down menu button is displayed as follows:
In the preceding example, the box-shadow attribute is set in the drop-down menu. This attribute is mainly used to add shadows, so that the drop-down menu looks like a card. This attribute specifies that the drop-down menu shadow is 0 in the horizontal direction, the shadow is 8 pixels in the vertical direction, the blur distance is 15 pixels, the shadow size is 0, and the shadow color is black, the transparency is 0.2.
The drop-down menu button uses the cursor attribute, which is mainly used to specify the type of the mouse cursor, that is, the cursor shape used when the mouse pointer is placed within the boundary of an element.
The following table lists all values of this attribute: You can move the cursor to the corresponding property value to view the shape of the cursor.
| Value |
Description |
| URL |
The URL of the custom optical indicator to be used. Note: A normal cursor is always defined at the end of the list to prevent the available cursor defined by the URL. |
| Default |
The default cursor, usually an arrow. |
| Auto |
By default, the cursor is set in the browser. |
| Pointer |
The cursor is a pointer indicating a link, that is, a hand. |
| Text |
This cursor indicates the text. |
| Wait |
The cursor indicates that the program is busy and displayed as a small circle in blue. |
| Help |
This cursor indicates available help and is displayed as an arrow with a question mark in the lower right corner. |
| Crosshair |
The cursor is displayed as a cross line. |
| Move |
This cursor indicates that an object can be moved. |
| E-resize |
This cursor indicates that the edge of the rectangle can be moved to the right (East. |
| Ne-resize |
This cursor indicates that the edge of the rectangle box can be moved up and right (North/East ). |
| Nw-resize |
This cursor indicates that the edge of the rectangle can be moved up and left (North/West ). |
| N-resize |
This cursor indicates that the edge of the rectangle box can be moved up (North. |
| Se-resize |
This cursor indicates that the edge of the rectangle box can be moved down and to the right (South/East ). |
| Sw-resize |
This cursor indicates that the edge of the rectangle can be moved down and left (South/West ). |
| S-resize |
This cursor indicates that the edge of the rectangle can be moved down (South ). |
| W-resize |
This cursor indicates that the edge of the rectangle can be moved to the left (West ). |
3. Alignment of the drop-down menu
If the float: left style is set in the drop-down menu, you also need to set left: 0, that is, the menu content is displayed from left to right from left: 0, otherwise it will go beyond the left window of the browser.
If the float: right style is set in the drop-down menu, it is displayed from left to right by default. The menu content will go beyond the window on the right of the browser, so you need to set right: 0, let the drop-down menu content go from right to left.
Align the drop-down menu Left
Drop-down menu item 1 drop-down menu item 2 drop-down menu item 3
Right
Drop-down menu item 1 drop-down menu item 2 drop-down menu item 3
In Chrome, when you move the mouse to the right drop-down button, the following is displayed:
4. drop-down images
In the following example, add an image to the drop-down menu:
Drop-down image
The most beautiful time left for the most beautiful scenery!
In Chrome, the following figure is displayed when you move the cursor to the image drop-down button:
5. navigation bar drop-down menu
In the following example, add a drop-down menu in the navigation bar:
Navigation bar drop-down menu
In Chrome, the drop-down button is displayed as follows:
How to create a simple CSS drop-down menu
CSS drop-down menu details
Special effects of CSS3 drop-down menu with simple underline-followed Effect