Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS Dropdown Menu

CSS Dropdown Menu

Use CSS to create a dropdown menu that appears when the mouse hovers over an element.


Dropdown Menu Examples

Example 1

Text Dropdown Menu

Runoob Tutorial

www.runoob.com

Example 2

Runoob Tutorial 1

Runoob Tutorial 2

Runoob Tutorial 3

Example 3

What you learn is not only technology, but also a dream!


Basic Dropdown Menu

When the mouse moves over a specified element, a dropdown menu appears.

Example

<

style

.dropdown

{

position:

relative

;

display:

inline-block

;

}

.dropdown-content

{

display:

none

;

position:

absolute

;

background-color:

#f9f9f9

;

min-width:

160

px

;

box-shadow:

0

px

8

px

16

px

0

px

rgba

(

0

,

0

,

0

,

0.2

)

;

padding:

12

px

16

px

;

}

.dropdown

:hover

.dropdown-content

{

display:

block

;

}

style

<div class="dropdown">
<span>

Hover over me!

span

<div class="dropdown-content">
<p>

Runoob Tutorial

p

<

p

www.runoob.com

p

div

div

Try it »

Example Parsing

HTML Part:

We can use any HTML element to open the dropdown menu, such as, or a
 


Try it »


Dropdown Content Alignment

float:left;

Runoob Tutorial 1

Runoob Tutorial 2

Runoob Tutorial 3

float:right;

Runoob Tutorial 1

Runoob Tutorial 2

Runoob Tutorial 3

If you want the right-floated dropdown menu content to be aligned from right to left instead of left to right, you can add the following code right: 0;

Example

.dropdown-content

{

   

right:

0;

}

Try it »


More examples

Image Dropdown
This example demonstrates how to add an image to a dropdown menu.

Navbar Dropdown
This example demonstrates how to add a dropdown menu to a navigation bar.