Spiegato, Home

Technology and Gadgets

How Do I Create Drop down CSS Menus?

  • Published by Spiegato
  • 3 min read

Cascading Style Sheets (CSS) is a name used to describe the way a Hyper Text Markup Language (HTML) or Extensible Markup Language (XML) document is formatted. It can be used for any type of XML document, but it is most often used with web pages written in HTML. CSS can be used to create drop down menus on web pages. Drop down CSS menus have a single text item shown until the visitor uses the mouse to hover over the menu, at which point the entire list of items is shown. The menu is created using the CSS identification and class tags.

Drop down CSS menus start with the ID selector. This selector looks like #. It is followed by the name of the ID. You can name the ID anything, but it should be descriptive so that others can read your code. For example, a drop down menu can use the code #drop1.

Create the class for the first item in the drop down menu by using the class selector, which looks like a period. The class will be part of the HTML list element. The list element is designated by the characters “li.” Create the top level class by typing “li.top.” The class description is contained between two curly braces.

The following example shows the entire CSS code for the first item in the list:

#drop1 li.top {font-family: Verdana, Geneva, san-serif;
font-size: 100%;
color: #FF00FF;}

Next, create a class for the items that will be hidden beneath the first item in the CSS menu. The class will describe the HTML unordered list, which is designated with the characters “ul.” The description will look essentially the same as the top-level menu item, with the addition of the words “display:none#59” at the beginning of the description. This indicates that the items in the unordered list will be hidden until the pointer hovers over the drop down CSS menu.

The following is an example of this portion of the CSS code:
#drop1 ul.link {
display:none#59
font-family: Verdana, Geneva, san-serif;
font-size: 100%;
color: #FF00FF;}
You will want to the drop down CSS menu to appear over the rest of the HMTL document. Otherwise, when the visitor hovers over the menu, it will push the rest of the document down the page to make room for the list. Setting the position element to absolute, will do this.
The code to set the position is:
#drop1{position:absolute;}
That is all that is needed for the CSS portion of the drop down menu. The rest of the drop down CSS menu is created in the HTML document using the “div,” “id,” “class,” “li” and “ul” elements. The “div” tag separates the menu portion of the document. Type

When you open the document in a web browser, the drop down CSS menu will appear as a single item on the page. When you move your mouse over the top item, the rest of the menu will appear. The rest of the text on the page will not move, but a portion will be hidden by the menu.

Key terms in this article

Related articles

  • What are Drop Down Menus?

    Drop down menus are lists of options that appear when a person selects an Internet icon with his mouse. It is referred to as a drop down menu because…

  • What Is an HTML Drop down Menu?

    A hypertext markup language (HTML) drop down menu is a web page form element. The menu can be used to show list of options, such as geographic regions…

  • How can I Create CSS Hover Effects?

    CSS hover effects are fairly simple to create, and basic hover effects can be quickly and easily implemented and modified with a number of other options…

  • How do I Create Padding in CSS?

    CSS padding allows an HTML coder to set the default padding or dead space outside of an HTML element. The benefit of doing this is that it saves the coder…

  • What Are the Different Types of HTML Menus?

    There are several types of HyperText Markup Language (HTML) menus, although implementing most of them requires the use of cascading style sheets (CSS), a…