CSS menus
the solution and article is good and points out the big problem is making this stuff work in CSS is IE. Other browsers such as Firefox have a .hover class that will work on any element. Alas , good old IE with its 90% share only does on links. The solution offered in is this article runs Javascript that adds an .over class to each element in our menu block. It then alters the CSS as follows:
li:hover ul{ display: block; } becomes:
li:hover ul, li.over ul{ display: block; }
Now the CSS menus work in IE if we only want a single level of subnavigation but I was not able to make them work with multiple levels of subnavigation . Then I found a great solution at http://www.xs4all.nl/~peterned/csshover.html. This solution has an impressive piece of Javascript that the author wisely attaches as a behavior in the iefixes.css file as follows:
body{ behavior: url(/CSS/csshover.htc);
I like this as only dumb old IE will recognize the behavior and it is the only browser that needs the script. Hopefully with IE7 much of this nonsense will disappear as IE will move in line with standards. He solves the multiple level problem by using CSS specificity and here I quote"Every CSS rule has a certain specificity, which defines whether or not it overrules others. The higher the specificity of a rule, the more important it becomes. This specificity is calculated simply by counting the occurrences of ids, (pseudo-)classes and attribute selectors, and node names". This concept is used to hide submenus that don't need to be visible just yet, and only show them when needed later on. Very nice !
However it seems that some folks in Redmond have been reading the same information as they have come out with CSS adapters that will do the same thing as I was trying to accomplish http://www.asp.net/CSSAdapters/Default.aspx. the track that I was on would have worked nicely but Microsoft is doing the same thing with these adapters although the implementation is a little more complex than mine and handling the support for the code. I always choose the solution that puts the least work on me as in the end support and change are too biggest problems. The menus for my website were implemented using these and I like the result. The only problem that I have is that it is not easy to add client-side events to the menu items. there are times when one might want to handle the mouse click in javascript instead of Posting back (or firing a Page method event).
In my role as a consultant I try and convince my client to buy the Telerik controls are they really are the best solution I could find but as a fallback these CSS Adapters are almost as good. Of course there are many other controls in the Telerik set that are extremely useful.
