WebReference.com logo
tip archive  •   about  •   sitemap  •   contact  •   jobs  •   write for us  •   subscribe


[prev]

How to Style an Unordered List with CSS [con't]

Oracle DBA (IL)
Next Step Systems
US-IL-Lombard

Justtechjobs.com Post A Job | Post A Resume

If we use the CSS from example list one we get the following results.

Part Two/Step 1

The span information is displayed within each link, as you would expect. Our aim is to hide the span information and only show it on hover.

Styling

Step 2

Hiding the Span Information

To hide the spans all we need to do is style them using display none:

Part Two/Step 2

The span is now normally hidden from view.

Step 3

Showing the Span Information on Hover

All that is necessary to make the span show up is to style it using display block.

It is important to note that IE6 has a :hover bug such that it will only work if triggered by a change in properties of any of the following commonly used styles. In our case we have a change of background to trigger the :hover pseudo class.

Part Two/Step 3

If you now hover over each link it will expand to show the contents of the span.

Step 4

Moving the Span out of the Menu Links

This is not very user friendly as the menu items jump about and it's not very clear what is happening.

What we need is a method of placing the span information in a box of its own so that it doesn't affect the menu list. This can be done by giving the span an absolute position which will take it out of the normal page flow and allow us to position it where we like.

In order for us to control the absolute position relative to the menu we will need to give the menu a relative position:.

Part Two/Step 4

The span information has now been moved out of the menu links and placed to the right, but it could use a bit more styling.

Step 5

Setting up the Size and Color of the Span

Part Two/Step 5

The span is now neatly styled in a light grey box with a purple border with the image under the painter's name. The text, however, starts at the bottom right of the image.

Step 6

Styling the Span Image

It would be nice if the text were to start in line with the top of the image.

Part Two/Step 6

The text now starts in line with the top of the image.

Step 7

Styling the Span First Line

Just one last step before we are finished. It would be nice if the first line of the span stood out a bit more.

We can use the pseudo class :first-line to style just the painter's name and his birth/death dates:

Example List Two

It's done. We now have a pop up box with information about each menu item.

Part Three

Step One

Re-styling the Pop-up

We don't need to stop there.

Wouldn't it be nice if the pop-up box were to track our menu items instead of staying fixed at the top of the menu?

If we had a long list of items we wouldn't want to look to the top of the list to see the information; it would be much more convenient if it were to appear alongside each item.

With a little change of style this too is possible.

The current position of the span information is determined by the relative position styling of the #menu. If we were to give the links a relative position 'on hover' instead of the #menu then the spans would be absolutely positioned relative to each link.

To do this, remove the position:relative; from the #menu style and place it in the #menu a, #menu a:visited style instead.

Example List Three

We now have a pop-up information box that tracks the menu items. The top of the pop-up box is now in line with the top of each menu item. The exact position can be controlled by changing the top and left values of the 'hover span' style.

You may also enjoy:

Conclusion

From this tutorial you can see how easy it is to style this type of menu. I have given you the basic information which you can modify as you wish to fit in with the look of your page. The styling, as I have said in past articles, is left up to your imagination.

About the Author

Stu's Web site documents his attempts at understanding and exploring the possibilities of CSS. From standard navigation links to his more bizarre experimental techniques. All of his examples are produced with using just CSS—no JavaScript, or any other language, has been used in any of the examples. [Editor's note: Prepare to be amazed!]

Original: July 8, 2005

Social Bookmark


[prev]

Recent Articles

WebReference.com site name
Search Engine Optimization: Selecting and Embedding Keywords
Are Google's Language Translation Web Services Ready for Prime Time?
Installing and Using Meeplace, the Business Review CMS
internet.com site name
IBM DB2 10 for z/OS: Justifying the Upgrade
Living La Vida Colo: Choosing the Right Colocation Facility
FTC Concerns over Social Media Privacy Linger



The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers