cssmenu: simple dropdown menu using only CSS

These are more or less my notes of an effort to implement a very simple dropdown-like menu that is implemented purely in HMTL and CSS.

It is currently not tested for cross-browser compatibility (it apprears not to work in MS IE 5.0) but it should work in most Mozilla-based browsers. If you have any improvements, please send me an email.

This is just a small demo of an idea I had for useing CSS in a menu, it is not really production-quality just proof-of-concept.

First try

This solution basically trims the list items to the height of one line if the mouse is not over the list item. This causes the menu to expand one level if the mouse is over an item.

the CSS

ul.menu li {
  display: block;
  width: auto;
  height: 1em;
  overflow: hidden;
}

ul.menu li:hover {
  height: auto;
  overflow: visible;
}

the HTML

<ul class="menu">
  <li>
    Item1
    <ul>
      <li>Item1.1</li>
      <li>
        Item1.2
        <ul>
          <li>Item1.2.1</li>
          <li>Item1.2.2</li>
          <li>Item1.2.3</li>
        </ul>
      </li>
      <li>
        Item1.3
        <ul>
          <li>Item1.3.1</li>
          <li>Item1.3.2</li>
        </ul>
      </li>
    </ul>
  </li>
  <li>Item2</li>
</ul>

the result

open issues and notes

Second try

This tries to make an effort of only showing the menu if an option is clicked. This solution only shows the lists if they have a pointer over them or have their parent activated. The HTML code is the same as in the previous example.

the CSS

ul.menu ul {
  display: none;
  position: relative;
  bottom: 1em;
  padding-top: 1em;
}

ul.menu li:active ul {
  display: block;
}

ul.menu ul:hover {
  display: block;
}

the result

open issues and notes