Home arrow JavaScript arrow Page 4 - Using the YUI Menu Control
JAVASCRIPT

Using the YUI Menu Control


I recently wrote an article that gave a general overview of the Yahoo! User Interface library, or YUI. It's a comprehensive library of utilities and controls written in AJAX for developers like you. Using it can save you time and frustration and throughout the course of this article, I'll be looking at just how easy it is to create a functional, attractive and effective navigation menu, using nothing but a little HTML and the library.

Author Info:
By: Dan Wellman
Rating: 4 stars4 stars4 stars4 stars4 stars / 20
May 02, 2007
TABLE OF CONTENTS:
  1. · Using the YUI Menu Control
  2. · Creating a Basic Menu
  3. · Rendering and Displaying the Menu
  4. · Changing the Styling

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using the YUI Menu Control - Changing the Styling
(Page 4 of 4 )

Once you've added any applicable sub-menus to your menu, you can also very easily change the styling to fit in with your existing or desired site theme. You can create and use your own style sheet if you wish, but I have found it far easier to edit the style properties found in menu.css instead of creating a new style sheet. For example, you can make the text of your menu and sub-menus bold just by adding the font-weight:bold; rule to the div.yuimenu selector at the very top of the file. You could also take away the underlining text-decoration property when a menu item is rolled over by changing the underline property to none in the div.yuimenu li.selected a.selected, div.yuimenubar li.selected a.selected selector, which is located about halfway through the file. To change the roll-over color, simply change the background-colour property of the div.yuimenu li.selected, div.yuimenubar li.selected selector to whatever color you prefer.

The last thing that you might want to do is change the image that denotes the menu item has a submenu. By default it is a right-facing angle bracket type thing. This is the most complex change that you'll need to make, but can still be done very easily. First of all, you'll need a couple of images, called arrow_nrm.gif and arrow_hov.gif (I'm trying to keep to a similar naming convention to Yahoo!), which should be saved to the assets folder. Next, open the menu.css file in your text editor and find the div.yuimenu li.hassubmenu em.submenuindicator, div.yuimenubar li.hassubmenu em.submenuindicator selector. You should change the height and width properties to match those of your image. Also change the background-image rule so that it points to your image instead of map.gif.

Now, copy all of the rules, beginning with display up to background-repeat. Now scroll down until you find the div.yuimenu li.hassubmenu em.submenuindicator.selected selector. Remove the rule that it currently holds and paste in the code block you just copied, but this time change the background-image rule to arrow_hov.gif. Now save the file and open yuimenu.html in your browser. Your custom image should be visible.

This is just one of the many ways that the versatile menu control can be used as a quick and easy way to add navigation menu functionality to your site. The menu will work and appear identical in most modern browsers (IE6, IE7, FireFox 1 and 2.0 for sure), so this saves you from the usually long and laborious task of refining and modifying your code to get it working across browser platforms. There is tons more information on the Yahoo! Developer site, so be sure to check it out when you've finished playing around with this example.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials