Skip to main content

CSS Right-aligned Dropdown

Adding right: 0; makes the dropdown menu open from right to left, rather than from left to right.

Example

Prompt
Create a page demonstrating right-aligned dropdown content. Show two dropdown buttons side by side: one labeled "Left" floated left with dropdown-content using left:0, and one labeled "Right" floated right with dropdown-content using right:0. The dropdown buttons have green background (#4CAF50), white text, 16px padding, 16px font-size, no border, pointer cursor. On hover the button background changes to #3e8e41. The dropdown container is position relative, display inline-block. The dropdown-content is hidden by default, position absolute, right:0, background #f9f9f9, min-width 160px, box-shadow 0px 8px 16px 0px rgba(0,0,0,0.2), z-index 1. Links inside are black, 12px 16px padding, no underline, display block. Link hover background is #f1f1f1. On dropdown hover, show the content. Include a heading "Aligned Dropdown Content" and a paragraph explaining the left/right properties.
Output: complete HTML page

CSS Dropdown Image

A dropdown box can hold an image and other content as well.

Example

Prompt
Create a page demonstrating a dropdown with an image. A div with class "dropdown" contains a small thumbnail image (100x50) and a hidden dropdown-content div. The dropdown-content shows a larger version of the same image (300x200) and a description div with text "Beautiful Cinque Terre" with 15px padding and centered text. The dropdown container is position relative. The dropdown-content is hidden by default, position absolute, background #f9f9f9, min-width 160px. On hover, the dropdown-content is displayed. Use "img_5terre.jpg" as the image source with alt text "Cinque Terre". Include a heading "Dropdown Image" and a paragraph "Move the mouse over the image below to open the dropdown content."
Output: complete HTML page

CSS Dropdown Navbar

A navigation bar can also contain a dropdown menu.

Example

Prompt
Create a page with a dropdown menu inside a navigation bar. Use an unordered list with list items for Home, News, and a Dropdown item. The body has margin and padding 0. The ul has no list-style, no margin/padding, overflow hidden, background-color #38444d. List items float left. Links and the dropbtn have display inline-block, white color, centered text, 14px 16px padding, no underline. On hover, links and the dropbtn get a red background. The dropdown list item has display inline-block. The dropdown-content is hidden by default, position absolute, background #f9f9f9, min-width 160px, box-shadow 0px 8px 16px 0px rgba(0,0,0,0.2), z-index 1. Links inside dropdown-content are black, 12px 16px padding, no underline, display block, text-align left. On hover they get background #f1f1f1. On dropdown hover the content is shown. Include a heading "Dropdown Menu in Navbar" and paragraph "Hover over the Dropdown link to see the dropdown menu."
Output: complete HTML page