Click here to Skip to main content
Click here to Skip to main content

Pure CSS Menus

By , 19 Dec 2003
 

Introduction

Have you ever heard that it is not possible to create pure CSS dynamic menus for IE? Am sure you had. Do you believe it? Better don't...

Purpose of this article

The purpose of the project - to build dropdown menus using only CSS that work on IE. Starting with this I extended the code to allow it work on some other well-known browsers.

The purpose of the article - more or less educational and gives main overview of a some "hidden" and rearly unused, browser features. As well as showing some tricks for those who are curious. In addition it can be used by (un)skilled developers to get some ideas (code) for their projects.

Reader's skill requirements

Actually I was thinking whether to mark this as an "Advanced". But I am sure even low skilled people should understand it well. So, you will need basic knowledge of CSS and HTML to read it. There are some articles in codeproject.com that will explain enough to catch this one.

What is different from the other's CSS menus?

I've been searching for long time the web for CSS menus and didn't find pure CSS solution that works on IE. Sure, I found some interesting ideas on different sites. They lead me to this one. It is not perfect, and the code is not clean, but I do not have enough time to make all the thinks right (even to check the grammar). The most interesting alternate solution I have found (uses some JavaScript) is based on adding the hover pseudo-class to the LI element. Never thought it is possible...However, I never thought that no script dropdown menus are possible on IE at all...

The main difference between my CSS menus and the other ones is that my work on IE. All of the solutions I found use LI as main element for the :hover pseudo-class, but Microsoft decided to attach it only to the A element. Most of the sites note that their menu will work only on Opera 7.x or Mozilla. But these browsers are used by less than 5% of the people! The beauty of the pure CSS menus cannot be seen on the most popular browser? Not anymore.

So lets start..

What is a CSS menu?

Ok, move your mouse over these two words...

What is a pure CSS menu?

This is a dynamic menu that doesn't use scripts (e.g. JavaScript), but uses only CSS styling and some html.

Incredible?

Let's see the code:
<STYLE type=text/css id="default" title="default" name="default">

*::-moz-any-link br,*:-moz-any-link br { 
/*a workarround for mozilla*/
display:none;
}
div#menu * {
  cursor: pointer; /*because IE displays the text cursor 
if the link is inactive*/
}
.disabled {
   color: red !important;
   background: none !important;
}
div#menu {
   background: #F5F5DC;
   font: 10px Verdana, sans-serif;
   height: 15px;
   white-space: nowrap;
   width: 100%;
}

div#menu .a {
   background: #F5F5DC;
   border: 1px solid #F5F5DC;
   color: #000000;
   text-decoration: none;
}

div#menu .a table {
   display: block;
   font: 10px Verdana, sans-serif;
   white-space: nowrap;
}

div#menu table, div#menu table a {
   display: none;
}

div#menu .a:hover, div#menu div.menuitem:hover {
   background: #7DA6EE;
   border: 1px solid #000080;
   color: #0000FF;
   margin-right:-1px; /*resolves a problem with Opera 
not displaying the right border*/
}

div#menu .a:hover table, div#menu div.menuitem:hover table{
   background: #FFFFFF;
   border: 1px solid #708090;
   display: block;
   position: absolute;
   white-space: nowrap;
}

div#menu .a:hover table a, div#menu div.menuitem:hover table a {
   border-left: 10px solid #708090;
   border-right: 1px solid white; /*resolves a jump problem*/
   color: #000000;
   display: block;
   padding: 1px 12px;
   text-decoration: none;
   white-space: nowrap;
   z-index: 1000;
   
}

div#menu .a:hover table a:hover, div#menu div.menuitem:hover table a:hover {
   background: #7DA6EE;
   border: 1px solid #000000;
   border-left: 10px solid #000000;
   color: #000000;
   display: block;
   padding: 0px 12px;
   text-decoration: none;
   z-index: 1000;
}

td {
   border-width: 0px;
   padding: 0px 0px 0px 0px;
}
.menuitem {
   float: left;
   margin: 1px 1px 1px 1px;
   padding: 1px 1px 1px 1px;
}

.menuitem * {
   padding: 0px 0px 0px 0px;
}
#other {
  height: auto;visibility: visible;
}
#moz{
  height: 1px;visibility: hidden;
}
#moz::-moz-cell-content{
  height: auto; visibility: visible;
}
#other::-moz-cell-content{
  height: 1px; visibility: hidden;
}
#holder {
  width: 100%;
}

</STYLE>

<TABLE id=holder>
    <TR>
        <TD id="other">
            <DIV id="menu">
                <DIV class="menuitem">
                    <a class="a" href='#'>File<BR>
                    <TABLE>
                        <TR>
                            <TD><a href=#2>Open ili op dulgo</A></TD>
                        </TR>
                        <TR>
                            <TD><a href=#3>Save</A></TD>
                        </TR>
                        <TR>
                            <TD><a href=#4>Close</A></TD>
                        </TR>
                    </TABLE>
                </DIV>
                <DIV class="menuitem">
                    <A class="a" href="#11">Help<BR>
                    <TABLE>
                        <TR>
                            <TD><a class="disabled">..</A></TD>
                        </TR>
                        <TR>
                            <TD><a href=#13>Index</A></TD>
                        </TR>
                        <TR>
                            <TD><a href="#14">About</A></TD>
                        </TR>
                    </TABLE>
                </DIV>
            </DIV>
        </TD>
    </TR>
    <TR>
        <TD id="moz"> Mozilla specific menu!
            <DIV id="menu">
                <DIV class="menuitem">
                    <a class="a" href='#'>Filezilla</A>
                    <TABLE>
                        <TR>
                            <TD><a href=#2>Open</A></TD>
                        </TR>
                        <TR>
                            <TD><a href=#3>Save</A></TD>
                        </TR>
                        <TR>
                            <TD><a href=#4>Close</A></TD>
                        </TR>
                    </TABLE>
                    </a>
                </DIV>
                <DIV class="menuitem">
                    <A class="a" href="#11">Helpzilla</A>
                    <TABLE>
                        <TR>
                            <TD><a class="disabled">..</A></TD>
                        </TR>
                        <TR>
                            <TD><a href=#13>Index</A></TD>
                        </TR>
                        <TR>
                            <TD><a href="#14">About</A></TD>
                        </TR>
                    </TABLE>
                    </A>
                </DIV>
            </DIV>
        </TD>
    </TR>
</TABLE><BR>

What is going on here?

I won't teach you how to use CSS, this is not the point of my article. Therefore I will start from the core of this stylesheet - the ':hover' pseudo-class. Yes it is a class! It means: a selector can inherit another selector that includes ':hover'. In our case 'A:hover TABLE' selects '<TABLE> in <A> hovered by the mouse'. Further part of the trick is that we have a table with its display property set to none (meaning invisible). This table is between an anchor tags (<A>,</A>). Microsoft said that this may cause strange behavior on IE, but I didn't noticed any...

Why we use a table? This is because it will successfuly detach the nested anchors we want to use from the main anchor. Actually it doesn't on Mozilla 0.7 and I still havn't found a no JavaScript solution. Direct nesting of anchors is not allowed by Microsoft, therefore the table is a workaround (or a hack) for IE. As I know only a table does the work.

So, what do we have here? 2 tables with anchors inside an anchor.

        <A class="a" href="#11" >Help<BR>
        <TABLE cellpadding="0" cellspacing="0" border="0">
            <TR>
                <TD><a href="#12">Howto</A></TD>
            </TR>
            <TR>
                <TD><a href="#13">Index</A></TD>
            </TR>
            <TR>
                <TD><a href="#14">About</A></TD>
            </TR>
        </TABLE></A>

They are hidden.

div#menu .a table {
   display: none;
   z-index:-1;
}

The browser shows the contents of the anchor when the mouse moves over it and applies the style:

  • For the text of link:
div#menu .a:hover {
   background: #7DA6EE;
   border: 1px solid black;
   color: black;z-index:0;
}
  • For the dropdown table that we use for sub menus: The key to all - shows the dropdown.
div#menu .a:hover table{
   background: White;
   display: block;
   position: absolute;
   width: 125px;z-index: 0;
   border: 1px solid #708090;

}
  • For the links inside the sub menus:
div#menu .a:hover table a {
   display: block;
   color: Black;
   text-decoration: none;
   padding: 1px 12px;z-index:1000;
}

If we hover one of the links into the submenu the browser applies:

  • For the links inside the sub menus:
div#menu .a:hover table a:hover {
   display: block;
   background: #7DA6EE;
   color: black;
   text-decoration: none;
   padding: 0px 11px;
   border: 1px solid black;z-index:1000;
   visibility: visible;
}
  • The style of the links in the dropdown.
div#menu .a:hover table a {
   display: block;
   color: Black;
   text-decoration: none;
   padding: 1px 12px;z-index:1000;
}

May be you did noticed some 'z-index' properties. They are workaround for some problems I found while testing the menu.

Improvements

You can extend the whole thingy to have sublevels in the dropdown menus. Just insert another div '.menuitem'(with its content and the same structure) instead of some link into the parent's table. Now you have sublevel into your menu. You will have to remove the <BR> tag to let the menu show aside. In addition you have to create number of copies of the classes .menuitem and .a with the same properties but with different name for every sublevel. Seem lots of work, but you can simply add their selectors to the appropriate section in the style sheet

A complete description how to do it I will add another time. Of course this is pure CSS and you can customize everything. The possibilities are infinite - your imagination is not...

Style switching (Skins)

If you wish to add different skins for the same menu that the user can switch, you have to add them as different STYLE sheets and name them with id='some_name' (for IE) and name='some_name' (for others). For not applying both styles you have to disable all except the default one by adding "disabled" into the style defining tag (no matter whether you link it or use the inline syntax). Mozilla and Opera allow switching of the named styles from inside the browser. Usually these browsers do not apply all styles that are defined with name="..." and DO ignore id="...". Also they threat name='default' as default stylesheet and name='alternate' as alternative stylesheets. You can define the name of the style that the user will see by the title="..." property. As an example: the live demo on this page include these definitions:

<STYLE type=text/css id="alternate" title="Blue" name="alternate" disabled>
...<STYLE>

<STYLE type=text/css id="default" title="Default" name="default">
...<STYLE>

Note the naming conventions and order, which I strongly recommend you to follow.

IE doesn't have built-in switching of css styles so we have to implement one (no way we have to use some JavaScript):

Click one to choose and go up to see the changes:


Which has this simple code:
<ul>
  <li onclick="document.styleSheets('default').disabled=false; 
          document.styleSheets('alternate').disabled=true;">
  <a>Default</a>
  </li>
  <li onclick="document.styleSheets('alternate').disabled=false; 
            document.styleSheets('default').disabled=true;">
  <a>Blue</a>
  </li>
  <li onclick="document.styleSheets('alternate').disabled=true; 
          document.styleSheets('default').disabled=true;">
  <a>No Stylesheet</a>
  </li>
</ul>

Warning! This is just a brief overview! Reloading the page will reload the default state of the stylesheets! Therefore for a real purpose you have to use cookies or serverside scripts to keep the users choice, which is not the point of the article. In adittion the above code works only on IE.

In conclusion

I definitely propose using a CSS menu in your website (web application), because most of the problems and bugs of the JavaScript menus are escaped. Such problems are usually caused by strange firing (or not firing) of mouse events by IE. Furthermore some browsers are able to switch off its Script support and for sure doesn't support M$'s JavaScript!

If the browser does not support CSS it will still show all of the links (you can try the above style switcher to turn off the styles). It will show the Mozilla menu too.

The 'Mozilla problem' - the links inside the submenus don't work. It is not possible to open into the same page (but work with shift+click). See 'bugs'.

I hope all that was helpful. Have a nice day.

Updates

  1. The problem with the <br> on Mozilla is resolved by adding this code into the stylesheet:
    a br,a:hover br { /*workarround for mozilla*/
     float:left;width:0px;padding:0px 0px 0px 0px;}
    

    The main code is corrected too
  2. The main links were separated, and the pixel-jump bug corrected.
  3. Added support of disabled items.
  4. Added Mozilla specific(alternate) menu, point 1. is no longer necessary. See 'bugs'.
  5. 21st dec: Added the skin section (added an alternate style not included in the visible code)
  6. 21st dec: Almost completed the Mozilla's section (have some style bugs, but works)
  7. 21st dec: Added/rewritten some parts of the article
  8. 21st dec: Added the source of the live demo for download as .zip file.

Known bugs

By default the links on the submenus don't work on Mozilla. But I did found some kind of solution for this. It is based on inserting a specific menu for this browser again without any scripting. Inspect the parts of the code where is mentioned Mozilla (or 'moz'). You will see that the HTML part doesn't have nesting of anchors (the last </a> is moved where it should stay usually). In the CSS part I use some undocumented selectors - pure Mozilla specific, and added :hover selector for the divs which is supported by Mozilla. It still have some minor style misbehavior.

I have a comment (by Nick Young) that it won't work on Netscape. I am sure the problem is the same as Mozilla. Have to search some more info about it. The eventual fix will require minor changes because the alternate code should work OK on Netscape.

Notes:

  • The code extractions may slightly differ from the main code. There are no significant changes that require updating them too.
  • The page is tested by me on Internet Explorer 5, 5.5, 6, Opera7.23 and Mozilla 0.71. I think it will work on some previous versions of these browsers.
    • P.S. Please, do not post me links to sites for CSS Menus, I've seen all(!) that Google found. None of them involve JavaScript menus for IE!
    • P.P.S. Don't forget to vote :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Venimus
Bulgaria Bulgaria
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generaldoesnt work in IEmemberMohsenVafa19 May '09 - 21:03 
unfortunately it doesn't work in IE :(
GeneralDon't work on Vista - FF 3.0.8 - IE 7.0.6001.18000memberVincent DUVERNET (Nolmë Informatique)3 May '09 - 4:47 
Hi, I've tried this code but it don't work correctly :/
 
- Under IE : Look is Ok but rollover on sub menu don't work. Mouse can't go on.
 
- Under FF : a strange graphic bug between Menu and SubMenu, there's a blank & gray space but other things seems to be ok.
 
any idea ?
GeneralCSS menu enhancements requiredmemberweb9613 Aug '07 - 2:37 
First off, I really like this CSS menu and it offers a really nice look and feel.
 
In aligning this menu to my app I use a single drop down containing several options. Each option provides additional checkboxes on my app form. I would like to add a hidden field containing the menu select(menu Array) so IE back will keep the checkboxes visible when doing a postback. Currently, the checkboxes remain selected but are hidden from the user. So I need to retain that menu selection somehow.
 
Another option in my particular case is to include new functionality within the hide part of the js to clear any checkbox selections. So if the requests the menu option to become hidden the checkboxes are cleared.
 
So, basically I have two questions for the forum.
 
1. how to save the menu array on the form during pagination or IE Back.
 
2. include a checkbox deselect during a switch_id.className=hide.
 
Thanks for your suggestions.
 
web96
 
web96
Generalasp.net & email attachmentmemberaransiola16 May '07 - 23:34 
do asp.net 2005 have support for multiple email attachment
pls help with some code.
 
t.aransiola
GeneralThanks for code - got it working in IE using Cold Fusion for data sourcememberJim Pap21 Dec '06 - 9:41 
No change to CSS. Used Cold Fusion to create the queries.
 

<cfquery datasource="#request.DSN2#" name="get_cats">
select catid,category,seqlevel
from ConCatAccess
where (accesslevel <= #request.access#)
   and (concept = '#request.concept#')
   order by seqlevel
</cfquery>
 

<TABLE id=holder>
      <TR>
         <TD id="other">
            <DIV id="menu">
               <cfloop query="get_cats">
           <!--- Get the sub menu items for this concept   --->
           <cfquery datasource="#request.DSN2#" name="get_subcats">
          select subcategory,url
          from subconcatacc
          where catid=#get_cats.catid#
             and   (subaccesslevel <= #request.access#)
             and (concept = '#request.concept#')
          order by seqlev
           </cfquery>                   
                   
           <DIV class="menuitem">
                     <a class="a" href='#'><cfoutput>#Category#</cfoutput><BR>
                           <TABLE>
                <cfloop query="get_subcats">
                                    <TR>
                                          <TD><a href="<cfoutput>#get_subcats.url#</cfoutput>"><cfoutput>#get_subcats.subcategory#</cfoutput></a>
                                          </TD>
                                    </TR>
                </cfloop>
                           </TABLE>
                        </a>
                     </DIV>
     </cfloop>
         </DIV>
      </TD>
   </TR>
</TABLE>
QuestionManage to get it work on firefox 2.0 but not on IE 6memberlodginginparis11 Dec '06 - 9:54 
Bonjour,
 
I did manage to get it work on firefox 2.0 but not on IE 6 or Firefox 1.
 
Anyone had the same problem ?
 
sb
QuestionHow to create dynamic cssmemberExelioindia30 Oct '06 - 0:19 
Hi ,
 

I want to create an dynamic css. The color's and font values are entered by the user at run time through asp.net page. How to do this??
 
Plz give me an suggestion
 
Bye
 
Know is Drop, Unknown is Ocean

GeneralIE7memberAlan Hendry28 Aug '06 - 22:58 
In IE7 (release candidate 1) -
When you hover on the menus the submenus drop down OK
But when you try to move your mouse to the submenus, the submenus disappear

GeneralRe: IE7memberPwbriggs5 Dec '06 - 11:53 
I am having the same issue with my app in IE7. How do I fix this? Please help!
GeneralRe: IE7memberAlan Hendry2 Jan '07 - 1:10 
There is a border around the entire drop down menu.
There is a onmouseover and a onmouseout, for each item in the drop down menu.
I think that when you move your mouse from the item to the border
the onmouseout is invoked.
The obvious answer is to try removing the border (see the style sheets).

GeneralRe: IE7memberdragon101137 Aug '08 - 5:53 
I'm still having a problem with the table hiding as soon as the i move the cursor from the link.
I removed the borders from the style sheets and from the table itself...
 
Please what other tips do you have?
GeneralRe: IE7memberAlan Hendry7 Aug '08 - 6:15 
Did you remove border, or specify borderBlush | :O ?
 
For a completely different approach to css only menus you might consider
http://www.grc.com/menu2/invitro.htm
GeneralRe: IE7memberAlan Hendry7 Aug '08 - 6:17 
This site replaced equal zero by a smiley
I probably meant borderBlush | :O
GeneralRe: IE7memberdragon101138 Aug '08 - 8:07 
how do you totally remove the border?
Generalvery very urgentlymembersurshbabuk19 Jun '06 - 0:25 
hi friends,
this is sasi, in this code project i saw creating menus using css.
url:
GeneralRe: very very urgentlymemberrajhans8426 Jul '07 - 0:29 
Very simple idea is there.. you can fetch the menu items from database and put them in the div and apply css to that particular div..
 
Don't have a loan we can do it for you. Just try out our new home loan plans

Generalbouncingmemberlonecrow23 Mar '06 - 9:19 
One of the hover effects causes the words to bounce left on hover. Drives my nutty. I think maybe it was *supposed* to be a button type effect but it sure doesn't work for me. I am trying to decipher the CSS to fix it but can't find the the right class.
 
It looks like the menuitem hover class adds a 1px left border causing the menu to shift or bounce to the right. I can either add a 1px border to the class the same color as the background or remove the 1px border on the hover.
 
Anyway, I am not new to CSS but it is taking me shockingly long to figure it out so if anybody has the fix please let me know.
 
Cheers
GeneralRe: bouncingmemberlonecrow23 Mar '06 - 10:01 
Fixed it for myself. Removed the border and the Opera hack from this selector:
 

div#menu .a:hover, div#menu div.menuitem:hover {
background: #7DA6EE;
border: 1px solid #000080;
color: #0000FF;
margin-right:-1px; /*resolves a problem with Opera
not displaying the right border*/
}
 
Changing to this below stopped the bouncing in IE and firefox with no other real effects. Might be a problem in Opera but...well the whole solution does not appear to work in Opera 7.23 any way.
 
div#menu .a:hover, div#menu div.menuitem:hover {
background: #7DA6EE;
color: #0000FF;
}

 

 

GeneralSubmenus work just fine with little adjustmentmemberJob de Noo10 Feb '06 - 1:19 
if you adjust the code a little bit you can get submenu's.
Here is some code, it is not verry beautifull but ok, also i didn't include the mozzila hack but that must almost work the same
 
here is the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE id=default title=default type=text/css name="default">
/* the Default theme */
*::-moz-any-link br,*:-moz-any-link br {
/*a workarround for mozilla*/
display:none;
}
div#menu * {
     border-collapse: collapse; /*removes the cell-borders*/
     cursor: pointer; /*because IE displays the text cursor if the link is inactive*/
}
 
div#menu {
   background: #efebde;
   height: 15px;
   white-space: nowrap;
   width: 10%;
}
div#menu .a {
   background: #F5F5DC;
   border: 1px solid #F5F5DC;
   color: #000000;
   text-decoration: none;
}
div#menu .a table {
   display: block;
   font: 10px Verdana, sans-serif;
   white-space: nowrap;
}
div#menu table, div#menu table a {
   display: none;
}
div#menu .a:hover {
   color:black;
   background: #7DA6EE;
   border: 1px solid #000080;
   color: #0000FF;
   margin-right:-1px; /*resolves a problem with Opera not displaying the right border*/
}
 
div#menu .a:hover table#niv1 {
   background: #FFFFFF;
   border: 1px solid #708090;
   display: block;
   white-space: nowrap;
   position:absolute;
}
 

div#menu .a:hover table#niv1 a   {
   border-left: 10px solid #708090;
   border-right: 1px solid white; /*resolves a jump problem*/
   color: black;
   display: block;
   padding: 1px 12px;
   text-decoration: none;
   white-space: nowrap;
   z-index: 1000;
}
 
div#menu .a:hover table#niv2{
     display:none
}
    
div#menu .a:hover table#niv1 a:hover {
   background: #7DA6EE;
   border: 1px solid #000000;
   border-left: 10px solid #000000;
   color: #000000;
   display: block;
   padding: 0px 12px;
   text-decoration: none;
   z-index: 1000;
}
div#menu .a:hover table#niv1 a:hover table#niv2{
   background: #FFFFFF;
   border: 1px solid #708090;
   display: block;
   white-space: nowrap;
   position:absolute;
 
}
 

    
    
</style>
</head>
 
<body>
<DIV id=menu>
 
         <A class=a href="#">File<BR>
          <TABLE id = niv1>
               <TBODY>
                    <TR>
                         <TD><A href="#2">Open ili op dulgo
                              <table id=niv2> <tbody> <tr> <td>
                                   <a href="#21">open21</a>
                              </td></tr></tbody></table>
                         </A></TD>
                    </TR>
                    <TR>
                         <TD><a href="#31">save1</A></TD>
                    </TR>
                    <TR>
                         <TD><A href="#4">Close</A></TD>
                    </TR>
               </TBODY>
          </TABLE>
     </A>
 

     <A class=a href="#11">Help<BR>
          <TABLE id = niv1>
               <TBODY>
                    <TR>
                         <TD><A class=disabled>..</A></TD>
                    </TR>
                    <TR>
                         <TD><A href="#13">Index</A></TD>
                    </TR>
                    <TR>
                         <TD><A href="#14">About</A></TD>
                    </TR>
               </TBODY>
          </TABLE>
     </A>
</DIV>
</body>
</html>

GeneralUsing your excellent CSS menu on my site!memberpennymachines6 Feb '06 - 7:47 
Just to say thanks! Very useful stuff.
I've adapted your Pure CSS Menus on my site at www.pennymachines.co.uk to provide an alternative (noscript) menu for any of my visitors who abstain from JavaScript and Flash. Disable JavaScript to see it work. Not perfect, but yours is the only total non-JavaScript solution I've seen.
GeneralMenu not correctly working in Opera 8.01memberJack Snake10 Nov '05 - 7:29 
The menu is not completely working in opera V8.01. The colloured block on in the sub-menu's dissappear when you hover over an item with the mouse.....
GeneralModified Fly Out Menusussrich a1 May '05 - 15:14 
I modified CSS code originally written by Stu Nicholls. He has an awesome site dedicated to CSS at http://www.stunicholls.myby.co.uk/menus/snazzymenu.html. My modification was to add a fly-out menu. In FF, the page looks as intended. However, the page has problems in the latest version of IE. Can anyone point me in the right direction?
 
My test page is at: http://www.rigami.com/1234.htm
 
Thanks
GeneralRe: Modified Fly Out MenumemberDr Suess2 May '05 - 10:16 
You can look at my discussion on flyout menus below
 
Dr Suess
GeneralFlyout menusmemberDr Suess22 Apr '05 - 7:06 
Rose | [Rose] I am currently trying to create flyout menus for a website that I am developing. It must work in all common browsers, this means most flavors of IE and Netscape. The design specifications demand that they start on the left side of the page- and flyout over the content in the middle of the page. Basically I am updating a Cold Fusion site into C#.Net. I spent some time with what appeared to be an elegant menu that used behaviors in an htc file. However, while I was debugging, I noticed that several critical srcElements did not get correctly populated- and so the htc file failed in the middle. The comment you made that not all mouse behaviors get correctly passed into such files explains three frustrating hours for me. Rose | [Rose]
 
;PYour menu comes closer than anything I have worked with so far. However, when I try and move the File and Help from an across the top of the page style into a sidebar arrangement, I notice that that I have to start duplicate styles and I am getting some odd behavior. WTF | :WTF:
 
Do you have any helpful suggestions on how I might proceed?Laugh | :laugh: Wink | ;) Poke tongue | ;-P
 
Dr Suess
GeneralRe: Flyout menusmemberDr Suess2 May '05 - 9:51 
I have succeeded in getting Flyout menus to work in ASP.Net and C#. These are dynamically generated by the database, and created individually for each page. Here is the code in the code behind page:
namespace FlyoutMenusControl
{
     using System;
     using System.Collections;
     using System.Configuration;
     using System.ComponentModel;
     using System.Data;
     using System.Data.SqlClient;
     using System.Drawing;
     using System.IO;
     using System.Text;
     using System.Web;
     using System.Web.Util;
     using System.Web.UI;
     using System.Web.UI.WebControls;
     using System.Web.UI.HtmlControls;
     using System.Xml;
 

     public class FlyoutMenus : System.Web.UI.UserControl
     {
          protected System.Web.UI.WebControls.Label lblFlyoutMenus;
          int MENU_WIDTH = 100;
                        string[] sa_Caption_MainGroup_Array = new string[50];
          string[] sa_Href_MainGroup_Array = new string[50] ;
          int[] ia_xCustomer_MainGroup_Array = new int[50];
          string[] sa_GroupID_MainGroup_Array = new string [50] ;
          string [] sa_Type_MainGroup_Array = new string [50];
          int i_MainGroup_Index = 0;
          protected System.Web.UI.WebControls.Repeater employeeList;
          protected System.Web.UI.HtmlControls.HtmlAnchor A1;
          protected System.Web.UI.HtmlControls.HtmlGenericControl div_Menu;
          //page values
          string dsn_GeneralGlobalConnection = ConfigurationSettings.AppSettings["Northwind-dsn"];
 
          #region Web Form Designer generated code
          override protected void OnInit(EventArgs e)
          {
               //
               // CODEGEN: This call is required by the ASP.NET Web Form Designer.
               //
               InitializeComponent();
               base.OnInit(e);
          }
         
          /// <summary>
          ///          Required method for Designer support - do not modify
          ///          the contents of this method with the code editor.
          /// </summary>
          private void InitializeComponent()
          {this.Load += new System.EventHandler(this.Page_Load);
          }
          #endregion
         
          //protected System.Web.UI.WebControls.Repeater employeeList;
          protected System.Web.UI.WebControls.Label lblEmployeeXML;
 
          private void Page_Load(object sender, System.EventArgs e)
          {
          }         
 
#region "Output Menu Strings"
 
          public string pv_CreateMenuElements()
          {
 
               string s_Function = "CreateMenuElements";
               string s_Error = "";
               string s_InputSQL = "";
               string[] s_SecondCaptionArray = new string[20];
               string[] s_SecondHrefArray = new string[20];
               string[] s_xCustomerFromDB = new string[20];
               string s_GroupCaption = "";
               string s_GroupHRef = "";
               int i_NumSpaces = 0;
               string s_GroupXCustomer = "";
               int i_CurCustomer = 0;
               int i_index = 0;
               int CustomerID = 0;
 
               StringBuilder sb = new StringBuilder();
               string s_Style_Main_TR = "style=\"FONT-SIZE: 16px; COLOR: black; FONT-FAMILY: 'Times New Roman'; BACKGROUND-COLOR: #f1e9d8\"";
              
               int CustomerID = Convert.ToInt16(Application.Get("av_Customer"));
 
               if(i_CustomerID == 1)
               {
                    CustomerID = 1; //use the first Customer as it Customer
               }
               else
               {
                    s_InputSQL = "SELECT DISTINCT CompanyName " +
                         " FROM Customer " +
                         " WHERE CustomerId= " i_CustomerID;
                    CustomerID = 0;
                    using (SqlConnection cn_GenericSQL = new SqlConnection (dsn_GeneralGlobalConnection))
                    using (SqlCommand cm_GenericSQL = new SqlCommand (s_InputSQL, cn_GenericSQL))
                    {
                         try
                         {
                              cn_GenericSQL.Open();
                              CustomerID = Convert.ToInt16(cm_GenericSQL.ExecuteScalar());
                              cn_GenericSQL.Close();
                         }
                         catch (SqlException sx)
                         {
                              s_Error = s_Function + " failed. The generic error messages is:" + sx.Message;
                              sb.Append( s_Error);
                         }//catch
                    }//using
               }//else
 
                    //get the current Customer and all its siblings
                    s_InputSQL = "SELECT DISTINCT CustomerID, CompanyName, ContactName " +
                         " FROM Customer ";
              
                    using (SqlConnection cn_GenericSQL = new SqlConnection (dsn_GeneralGlobalConnection))
                    using (SqlCommand cm_GenericSQL = new SqlCommand (s_InputSQL, cn_GenericSQL))
                    {
                         try
                         {
                              cn_GenericSQL.Open();
                              SqlDataReader dr_DisplayData;
                              dr_DisplayData = cm_GenericSQL.ExecuteReader();              
              
                              while (dr_DisplayData.Read())
                              {//s_CaptionArray.GetValue(i).ToString()
                                   s_SecondCaptionArray.SetValue(dr_DisplayData.GetString(1).ToString(), i_index);
                                   s_SecondHrefArray.SetValue(dr_DisplayData.GetString(2).ToString(), i_index);
                                   s_xCustomerFromDB.SetValue(dr_DisplayData.GetValue(0).ToString(), i_index);
                                   i_index += 1;
                              }
                              dr_DisplayData.Close();
                              cn_GenericSQL.Close();
                         }
                         catch (SqlException sx)
                         {
                              s_Error = s_Function + " failed. The generic error messages is:" + sx.Message;
                              sb.Append( s_Error);
                         }//catch
                    }//using
              
                    //create the first level menu
                    for ( int i = 0; i < i_index; i++ )
                         {
                         s_GroupCaption = s_SecondCaptionArray.GetValue(i).ToString();
                         s_GroupHRef = s_SecondHrefArray.GetValue(i).ToString();
                         s_GroupXCustomer = s_xCustomerFromDB.GetValue(i).ToString();
 
                         //start menu
                         sb.Append("\n   <TR ");
                         sb.Append(s_Style_Main_TR);
                         sb.Append(" >\n");
                         sb.Append("         <TD class= \"td_MainMenu\">\n");
                         sb.Append("            <div class=\"div_menu\">\n");
                         sb.Append("                  <div class=\"menuitem\" >\n");
                         sb.Append("                     <a class = \"a_Flyout\" href='");
                         sb.Append(s_GroupHRef.ToString());
                         sb.Append ("'>");
                         sb.Append(s_GroupCaption.ToString());
                         i_NumSpaces = 20 - s_GroupCaption.Length;
                         for ( int i_Index = 0; i_Index < i_NumSpaces; i_Index++)
                              {      sb.Append("&nbsp;");   }
                         sb.Append("\n");
                         //start flyout menus to the side
                         i_CurCustomer = Convert.ToInt16 (s_GroupXCustomer.ToString());
                         sb.Append(pv_CreateFlyoutElements(i_CurCustomer));
                         //end flyout menus
                         sb.Append("                     </a>\n");
                         sb.Append("                  </div>\n");
                         sb.Append("            </div\n");
                         sb.Append("         </td>\n");
                         sb.Append("   </TR>\n");
                    }//for
               return sb.ToString();
          }//pv_CreateMenuElements()
 
          public string pv_CreateFlyoutElements(int i_XCustomer)
          {
               string s_Function = "CreateFlyoutElements";
               string s_Error = "";
               StringBuilder sb_Flyouts = new StringBuilder();
 
               try
               {
                    string s_InputSQL = "SELECT DISTINCT CompanyName, CustomerID, ContactName " +
                         " FROM Customer ";
 
                    using (SqlConnection cn_GenericSQL = new SqlConnection (dsn_GeneralGlobalConnection))
                    using (SqlCommand cm_GenericSQL = new SqlCommand (s_InputSQL, cn_GenericSQL))
                    {
                         try
                         {
                              cn_GenericSQL.Open();
                              SqlDataReader dr_DisplayData;
                              dr_DisplayData = cm_GenericSQL.ExecuteReader();    
                              //opening table
                              sb_Flyouts.Append("<Table id=\"Flyout_");
                              sb_Flyouts.Append(i_XCustomer.ToString());
                              sb_Flyouts.Append("\" width='");
                              sb_Flyouts.Append(MENU_WIDTH.ToString());
                              sb_Flyouts.Append("'   class='Flyout_Items' border='0' cellspacing='0' cellpadding='0'>\n");
              
                              while (dr_DisplayData.Read())
                              {//assign the values read from the database to an xml object
                                   sb_Flyouts.Append("\t<tr>\n");
                                   sb_Flyouts.Append("\t\t<td>\n");
                                   sb_Flyouts.Append("\t\t\t<b>");
                                   sb_Flyouts.Append("\t\t\t\t<a class=\"a_Flyout\" href=\"");
                                   sb_Flyouts.Append(dr_DisplayData.GetValue(2).ToString());
                                   sb_Flyouts.Append("\">");
                                   sb_Flyouts.Append(dr_DisplayData.GetValue(1).ToString());
                                   sb_Flyouts.Append("\t\t\t\t</a>");
                                   sb_Flyouts.Append("\t\t\t</td>\n");
                                   sb_Flyouts.Append("\t\t</tr>\n");
                              }
                              dr_DisplayData.Close();
                              cn_GenericSQL.Close();
 
                              sb_Flyouts.Append("\t</Table>\n");
                         }
                         catch (SqlException sx)
                         {
                              s_Error = s_Function + " failed. The generic error messages is:" + sx.Message;
                              return s_Error;
                         }//catch
                    }//using
               }
               catch (SqlException sx)
               {
                    s_Error = s_Function + " failed. The generic error messages is:" + sx.Message;
                    sb_Flyouts.Append( s_Error);
               }//catch
 
          return sb_Flyouts.ToString();
     }
 
#endregion
     }
}

 
Dr Suess

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 20 Dec 2003
Article Copyright 2003 by Venimus
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid