Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a menu in HTML without using Javascript?

Tags:

html

css

xhtml

menu

Since many years a GUI-standard are the menu-bars of applications with menus popping up, if you click or hover an entry in the menu-bar. Some websites implement this feature too, but they are using Javascript, as far as I can see. For different reasons Javascript can be a problem, so the question: Is this possible to implement without Javascript, only using HTML and CSS?

like image 621
Mnementh Avatar asked Oct 24 '08 12:10

Mnementh


People also ask

How do I create a menu section in HTML?

Create A SubnavUse any element to open the subnav/dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the subnav menu and add the subnav links inside it. Wrap a <div> element around the button and the <div> to position the subnav menu correctly with CSS.

What is the code for menu in HTML?

<menu>: The Menu element The <menu> HTML element is described in the HTML specification as a semantic alternative to <ul> , but treated by browsers (and exposed through the accessibility tree) as no different than <ul> . It represents an unordered list of items (which are represented by <li> elements).

How do I create a menu for my website?

In the left sidebar menu, navigate to Website > Navigation. Your default menu contains the pages that will automatically populate the default content of an advanced menu module. Use the dropdown menu to select an existing menu to update. To create a new menu, click + Add menu.


2 Answers

I've done something like this before, and it's a trick pulled off by placing the menu items in anchor tags, with submenus in hidden divs INSIDE those anchor tags. The CSS trick is to make the inner div appear during the a:hover event.

It looks something like:

<style>
    A DIV { display: none; }
    A:hover DIV { display: block; }
</style>
<a href="blah.htm">
    Top Level Menu Text
    <div><ul>
        <li><a href="sub1.htm">Sub Item 1</a></li>
        <li><a href="sub2.htm">Sub Item 2</a></li>
        <li><a href="sub3.htm">Sub Item 3</a></li>
    </ul></div>
</a>

Your mileage may vary...

EDIT: Internet Explorer 6 and lower do NOT support the :hover pseudo-class on other elements besides A. In more 'modern' browsers, it is accepted to be able to use this trick with LI, TD, DIV, SPAN, and most any tag.

like image 197
Jeff Fritz Avatar answered Sep 28 '22 07:09

Jeff Fritz


Have a look at CSS Menu Maker.

like image 28
extraneon Avatar answered Sep 28 '22 07:09

extraneon