I don't normally do "Guest Posts", but Daniel and I were talking about some hacking with CFMENU and CSS. He came up with some interesting findings and as he doesn't have a blog (hey Daniel, I know a good one!) I offered to post his findings here. Everything that follows is his work.
I started on a project a couple days ago that is intended purely for ColdFusion 8, since I wanted to incorporate cfmenu into it. Along the way with my tinkering of cfmenu, I wanted to know how to separate out the style information into a css file rather than using the 'style, menuStyle and childStyle' attributes of cfmenu and cfmenuitem.
I investigated the source of my page and learned that the scripts and css linking necessary to the cfmenu tags are automatically injected into the
tag of my page by ColdFusion. I eventually figured out that I could override the style statements in the css pages if I used an ID selector with the name of my menu.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
#myMenu {
background-color: #FFCCFF;
}
</style>
</head>
<body>
<cfmenu name="myMenu" type="horizontal">
<cfmenuitem name="acrobatInfo" href="http://www.adobe.com/acrobat" display="AcrobatI" />
</cfmenu>
</body>
</html>
This could also be done from a linked css document, which is ultimately what I was looking to accomplish.
My next goal was to remove the little arrows that indicated when there was a sub-menu. I have done many menus in the past and many of them I never used a sub-menu indicator (you will see why I call it a sub-menu indicator in a moment). Since I knew cfmenu used the Yahoo UI library to create the end result of the menu, I started searching through the YUI documentation for a solution.
The YUI Menu Documentation describes 6 particular classes, that once you understand what they are, it makes setting up style rules for them much easier.
- menu: a single vertical menu set
- menuitem: a single list item in a Menu
- menubar: a single horizontal menu set
- menubaritem: a single list item in a MenuBar
- hassubmenu: a menuitem or menubaritem that has a correspond submenu
- first-of-type: first of a menu, menuitem, menubar or menubaritem in a set
I wound up finding in the YUI Menu Documentation the answer I was looking for. A class named submenuindicator would allow me to control the arrows, but for some odd reason it refused to work. I found a note stating that this would not work for older versions of the YUI and this did apply to me. You can see what I found out about this in the ColdFusion 8 Forums, but suffice it to say I fixed the problem I was having. I used the YUI Menu Documentation to come up with this example, which shows how to remove the sub-menu indicator from the top level horizontal menu, but leave it in the lower vertical menus. I affect the 'visibility' property instead of the 'display', because I noticed in FireFox that my menu would break.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
}
/* Hide the Horizontal Bar sub-menu indicator, but not any of the Vertical */
#myMenu li.hassubmenu.yuimenubaritem em.submenuindicator {
visibility: hidden;
width: 0px;
height: 0px;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
}
#myMenu li.hassubmenu.yuimenubaritem li.hassubmenu.yuimenuitem em.submenuindicator {
visibility: inherit;
width: 8px;
height: 8px;
margin: 0px -16px 0px 10px;
}
/* Change Horizontal Bar delimiter - shows use of 'first-of-type' */
#myMenu li.yuimenubaritem {
border-color: #FF0000;
}
#myMenu li.yuimenubaritem.first-of-type {
border: none;
}
</style>
</head>
<body>
<cfmenu name="myMenu" type="horizontal">
<cfmenuitem name="acrobatInfo" href="http://www.adobe.com/acrobat" display="AcrobatI" />
<!--- the ColdFusion menu item has a pull-down submenu. --->
<cfmenuitem name="cfInfo"
href="http://www.adobe.com/products/coldfusion"
display="ColdFusion">
<cfmenuitem name="cfbuy" href="http://www.adobe.com/products/coldfusion/buy/" display="Buy" />
<cfmenuitem name="cfdocumentation" href="http://www.adobe.com/support/documentation/en/coldfusion/" display="Documentation">
<cfmenuitem name="cfmanuals" href="http://www.adobe.com/support/documentation/en/coldfusion/index.html##manuals" display="Product Manuals" />
<cfmenuitem name="cfrelnotes" href="http://www.adobe.com/support/documentation/en/coldfusion/releasenotes.html" display="Release Notes" />
</cfmenuitem>
<cfmenuitem name="cfsupport" href="http://www.adobe.com/support/coldfusion/" display="Support" />
</cfmenuitem>
<cfmenuitem name="flexInfo" href="http://www.adobe.com/flex" display="Flex" >
<cfmenuitem name="fldocumentation" href="http://www.adobe.com/support/documentation/en/flex/" display="Documentation" />
</cfmenuitem>
</cfmenu>
</body>
</html>
I do not pretend to be the best at writing css statements and this is just an example, but there might be some better statements to accomplish what I have done. I hope this is helpful to those of you that plan on using cfmenu.
Archived Comments
Ray...no examples?
Well, there is sample code. YOu mean an online example?
Do you have something you specifically need to know how to do? Maybe I could give you a hand.
Nothing specific...just wondering is all. Ray's usually really good about showing examples, so I was just curious.
This was a 100% guest post, so I didn't do a demo. Sorry. :) Of course, you can always try this yourself. ;)
I should have a new project up on RIAForge in a couple of weeks that will have an example of this. When I do and as long as I remember to come back and comment it, I will supply a link and the name of the project.
A quick clarification.
The classes actually are:
yuimenu - any yui menu div
yuimenuitem - any yui menu list-item
yuimenubar - Only a yui horizontal menu div
yuimenubaritem - Only a yui menu list-item under a horizontal menu bar
The other two classes were accurate. My solution worked under beta, but doesn't appear to work completely on CF8 official release. Like I said, when I finish my project, hopefully I will post it back here.
Ray,<br>
<br>
CFMenu is great. But when you combine it with another flex function like cfgrid, the menu drops down behind the grid. Is there anyway to fix this? I've searched far and wide for the solution but can't find it.<br>
<br>
I might need to drop cfmenu in our new Flex-y application. Say it ain't so Shane, 'er Ray, say it ain't so!<br>
<br>
Chris
You got me on that one. Can you try changing the z-index?
So what's the class to change the hover BG color for the Li?
Can some one point it out ...I've tried a few combinations ..but can't hit the nail
I found the answer to my z-index issue 2 posts back. Check it out here.
http://www.shareddynamics.c...
Thanks Ray. Your code helped me a lot to apply the CSS on CFMenu. My biggest problem is, it looks like there is compatibility issues for your code with IE7. I do not want the submenuindicator to be visible but this code only works on IE6 but does not on work on IE7 and Firefox 3.0.11. Does anyone have a suggestion on this one?
Thank you Ray for this post! With a bit of reading and testing I fixed a z-index issue by adding my own CSS below the closing head tag.