Content in the Javascript library assumes a sound understanding of ECMAScript, CSS, XHTML and DOM.

Expanding menu

Code listing for xc.css

  1. /*
  2. * date: 2003-01-09
  3. * info: http://inspire.server101.com/js/xc/
  4. */
  5. ul {
  6. list-style: disc;
  7. margin-left: 0;
  8. padding-left: 1.5em;
  9. }
  10. li.xc {
  11. list-style: none;
  12. }
  13. div.xcx, div.xcc {
  14. position: relative;
  15. display: inline;
  16. }
  17. li.xc>div.xcx, li.xc>div.xcc {
  18. position: static;
  19. margin-left: -1.5em;
  20. float: left;
  21. width: 1.5em;
  22. }
  23. div.xcx a, div.xcc a {
  24. position: absolute;
  25. left: -2em;
  26. }
  27. div.xcx>a, div.xcc>a {
  28. position: static;
  29. }
  30. div.xcx a:link, div.xcx a:visited,
  31. div.xcc a:link, div.xcc a:visited {
  32. color: #000;
  33. text-decoration: none;
  34. font-family: "Courier New", Courier, monospace;
  35. font-size: 75%;
  36. font-weight: bold;
  37. }

General notes

Hover over a line of code with your mouse to read the tips. A few of the styles listed above are optional, so here’s a quick rundown of what’s required for those that want to tinker about.

The expanding menu works by placing "[+]" or "[-]" text links inside list items. Since these links are part of each list item, and bullet points are normally outside (as markers), they do not line up. It’s not a good look (and not consistent with standard expanding menus).

The easiest way I’ve found to counter this, is to use margins to shift the list items back to align with the bullet points, then float the +/- control (using the same width) to push the text back into line. I’ve used 1.5em which seems to work well, however this is up to you, so long as you use the same size throughout.
[Note: em units are dependent upon font size. If you alter font size, you may have to adjust margin, padding, offset parameters accordingly. ]

Unfortunately, IE5.0 through 6.0 cannot handle the combination of negative margin and float. To counter this I’ve done a quick hack (which I hate doing) and used absolute/relative positioning on the control. The size adjustment mentioned above was needed for this.

The parent–child selector (which IE does not recognise) has been used to disable all the positioning code and specify the simpler margin/float solution for other browsers.

Messy, but it works (so far).

The rest of it, (colours, fonts, underlines, etc.) is open to your imagination.

[ inspire logo ]
Code in the javascript library is free to use. Enjoy! Feedback welcome.
© Ben Boyle 2003.