Css Horizontal Drop Down Menu Example Code

19.01.2020by
  1. Free Css Horizontal Menu
  2. Examples Of Drop Down Menus
  3. Drop Down Menu Html Css
  4. Free Css Horizontal Drop Down Menu
  5. Css Drop Down List Examples
  6. Css Horizontal Drop Down Menu Example Code List

Create a hoverable dropdown with CSS.

Horizontal CSS Menu. Text only CSS Menu; Simple Horizontal Menu; Simple Drop Down Menu; Easy Drop Down Menu; CSS Menu with images Dark; CSS Menu with images Bright; CSS Menu with images Red; CSS Menu with description; CSS Menu using one image; CSS Menu two lines; Vertical CSS Menu. This large horizontal drop-down menu simply shows the sub-menu when an item gets clicked. It’s inspired by the Microsoft.com drop-down menu. Some example media queries show how to adjust the menu for smaller screens. I surely can apply this creating drop down menus in homestead to my homepage. Anyway, it's done smoothly on the html5 css3 popup menu Server to see the horizontal dropline tab menu css2 0 drop down menu, but client PC cannot see the css menu with 4 stage drop down Menu. They can see only the Main Title only. I was in need of a very style agnostic drop down menu and struggling to find one. So I built one! I have made subtle change for submenus to use top an. See the Pen Simple CSS Dropdown Menu with Hover. Good point, Marcy. Is there a code sample for this, that ties into the example code above?

Demo: Dropdown Examples

Move the mouse over the examples below:

Dropdown Text
Other:

Basic Dropdown

Create a dropdown box that appears when the user moves the mouse over an element.

Example

<style>
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
<div>
<span>Mouse over me</span>
<div>
<p>Hello World!</p>
</div>
</div>
Try it Yourself »

Free Css Horizontal Menu

Example Explained

HTML) Use any element to open the dropdown content, e.g. a <span>, or a <button> element.

Use a container element (like <div>) to create the dropdown content and add whatever you want inside of it.

Wrap a <div> element around the elements to position the dropdown content correctly with CSS.

CSS) The .dropdown class uses position:relative, which is needed when we want the dropdown content to be placed right below the dropdown button (using position:absolute).

The .dropdown-content class holds the actual dropdown content. It is hidden by default, and will be displayed on hover (see below). Note the min-width is set to 160px. Feel free to change this. Tip: If you want the width of the dropdown content to be as wide as the dropdown button, set the width to 100% (and overflow:auto to enable scroll on small screens).

Instead of using a border, we have used the CSS box-shadow property to make the dropdown menu look like a 'card'.

The :hover selector is used to show the dropdown menu when the user moves the mouse over the dropdown button.

Dropdown Menu

Create a dropdown menu that allows the user to choose an option from a list:

This example is similar to the previous one, except that we add links inside the dropdown box and style them to fit a styled dropdown button:

Example

<style>
/* Style The Dropdown Button */
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
<div>
<button>Dropdown</button>
<div>
<a href='#'>Link 1</a>
<a href='#'>Link 2</a>
<a href='#'>Link 3</a>
</div>
</div>
Try it Yourself »

Right-aligned Dropdown Content

If you want the dropdown menu to go from right to left, instead of left to right, add right: 0;

Example

Try it Yourself »

More Examples

Dropdown Image

How to add an image and other content inside the dropdown box.

Hover over the image:

Examples Of Drop Down Menus



Try it Yourself »

Dropdown Navbar

How to add a dropdown menu inside a navigation bar.

Try it Yourself »

Today we’re going to look at how to make an HTML and CSS dropdown menu. No JavaScript or jQuery required!

Take a look at the demo to test it out and see what the end result looks like. The below HTML and CSS dropdown menu relies on z-index for some of the functionality, which can sometimes trip up beginners. If you get stuck, don’t hesitate to ask me a question.

After so much of trial I found solution for this problem is that someone started the installation with a wrong edition (32 vs. It’s puzzling, I am trying to install with 64 Bit version of SQL Server 2005 and it’s unable to locate the sqlcli_x64.msi, crazy thing is file is already available in installation folder and it’s showing me that error strange??? 64) edition and left the components there. Uninstall microsoft sql server express. Go to Add/Remove Programs and remove the existing SQL 2005 components, and then reinstall.

You might also like: Creating a Responsive Menu with HTML, CSS & jQuery

Table of Contents

  1. Skip to the HTML
  2. Skip to the CSS

1.)Â HTML Structure

Finished HTML

Ek Mukta Font

If you would like to use the same font as I’ve used you need a link to it in the header.

Wrapper and Nav

We start off with a wrapper div and give it a class of menu-wrap. Inside that wrapper, we put a nav and give it a class of menu.

First Unordered List

The first unordered list we’ll be using needs a class of clearfix (more on why when we write the CSS). Inside it, we’ll put a couple of links to act as menu content.

Nested Dropdown Menu

Css Horizontal Drop Down Menu Example Code

For the dropdown menu, we put another unordered list inside the one we already have and the HTML code is complete.

2.) CSS Styling

Finished CSS

Base Styling

We start the CSS with some base styling by setting a page background colour and setting up a clearfix. Don’t worry if you don’t have the background image it’s only a simple texture. You can grab it from the demo if needed.

The clearfix will stop an annoying bug where, if a parent element has a floated child element, it will disappear.

Menu Setup

Now we need to set up the outline of the entire menu and style a few ‘global’ elements (two or more elements with the same styling).

Dropdown Arrow

The arrow by default is quite large so we make the font-size smaller and remove the line-height. If we leave the default line-height the menu styling may become affected. Grey fox distress download adobe flash player.

Top Level Menu

To style just the top-level menu we can use the > symbol. It states that only the first child element preceding the parent will get the specified styling. E.g. .parent > child, only the top-level .child will get the styling whereas any children of .child that are also called .child won’t.

We also set a position:relative; on the parent list item in case it has a child (aka a submenu).

Bottom Level Menu

Here’s the fun part…and also the main point of this article. To style the sub menu we first need to position it. We do that with position:absolute;. By setting a percentage as the top instead of a fixed pixel value the submenu will always be positioned exactly at the bottom of its parent.

We also add z-index:-1;. This pushes the dropdown menu behind the everything else on the page, including the body element.

There’s also no opacity, this is so the submenu can fade in by using a transition.

For the transition you may want to use prefixed values if you’re targeting older browsers, however, for the purposes of this tutorial, we’ll be aiming at Firefox and Webkit based browsers (Webkit browsers include Google Chrome and Opera).

You may also wonder what the rgba(0,0,0,0.2) is. It states a colour (Red, Green and Blue) then the opacity (Alpha), in this case, it’s 20% (0.2)

To get the dropdown menu showing on hover we need to add a line that states when hovering over a list item, show its children. This has no effect on empty list items as they have no children to show.

The rest is the styling of the submenu list items and anchor links.

Conclusion

Some of the CSS used may be a little hard to wrap your head around at first, especially if you’re a beginner. If you need help in any way create a JSFiddle of your code and post the link to it in the comments.

Free Css Horizontal Drop Down Menu

Thank you for reading and I look forward to chatting with you below!

Css Drop Down List Examples

You might also like: Creating an Accordion with HTML, CSS & jQuery

Css Horizontal Drop Down Menu Example Code List

Resource:Â A Beginner’s Guide to HTML in Web Development.

Comments are closed.