Style Sheets
  Home arrow Style Sheets arrow Page 6 - Introduction to CSS Positioning Properties...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Introduction to CSS Positioning Properties Part 2
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2005-02-28

    Table of Contents:
  • Introduction to CSS Positioning Properties Part 2
  • The "clear" property
  • The "z-index" property
  • The "visibility" property
  • The "overflow" property
  • A simple drop-down menu using the "overflow" and "display" properties

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introduction to CSS Positioning Properties Part 2 - A simple drop-down menu using the "overflow" and "display" properties


    (Page 6 of 6 )

    First, let's show the corresponding CSS and markup code for the menu, and then explain what they do:

    <style type="text/css">

    .navbar {

         display: block;

         font: bold 11px "Verdana", Arial, Helvetica, sans-serif;

         color: #fff;

         padding: 2px;

         background: #00f;

         text-align: center;

    }

    a.menu:link,a.menu:visited {

         display: block;

         width: 100px;

         height: 18px;

         overflow: hidden;

         text-decoration: none;

    }

    a.menu:hover {

         display: block;

         width: 100px;

         height: 90px;

         overflow: visible;

         font: normal 11px Verdana, Arial, Helvetica, sans-serif;

         color: #000;

         background: #ffc;

         padding: 0px 0px 5px 0px;

         text-decoration: none;

    }

        

    </style>

    The HTML markup is listed below:

    <a href="#" class="menu">

    <span class="navbar">Products</span><br />

    Stereo Editors<br />

    Multitrack Editors<br />

    Expanders<br />

    Compressors<br />

    Equalizers</a>

    That's all of the necessary code to make our simple menu work. Let's explain our CSS declarations:

    We've defined a class "navbar" which will be displayed initially as the navigation element for our menu. As usual, we've styled the element using fonts, background colors, padding and the like. The only property to be noticed is "display: block." Since this element will be included within an <a> element, we need it to behave as a block-level element.

    Next, we've declared another class "menu," which acts as the menu for the navigation bar element. Here, we're taking advantage of each state for the "a:link" and "a:hover" pseudoclasses. Since our menu is built around the <a> element, we need to initially hide the menu items. That's what we do by setting a height of 18px and assigning the property "overflow: hidden" for the "a:link" state. This way, all of the menu items will be properly hidden since they exceed height.

    Then, for the a:hover state, we just assign a new width of 90px for menu items and set the overflow property to "visible." This causes the menu items to be displayed when the mouse it's hovered on the link. Quite simple, isn't it?

    The output for this simple drop-down menu is illustrated is the following sequence:

    We've created a simple but useful menu using the powerful CSS position capabilities, without the help of any JavaScript code and with little or no effort. Since most modern browsers offer support for these properties, our menu is pretty well suited for being implemented on websites that don't require sophisticated navigation systems.

    Summary

    In this article, we've looked closely at the most common CSS2 visual properties, which are strongly oriented to position elements in Web documents. Also, with the help of numerous examples, we were able to implement those properties in order to make them work for us in an efficient way. As usual with client-side techniques, we should always be aware of browser support. However, since old fourth-generation browsers are progressively being replaced by today's versions, we can take advantages of the benefits and capabilities available from using the newer CSS2 specifications.


    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.

       · In this second part, I describe some useful properties such as float, overflowand...
       · The comments posted previously are comming from me, the author.Thank...
       · Is very misleading while being utterly useless. A menu is a structured list of...
       · Dear Sir,Thank you for stopping at the article and take some time to read...
       · I can't see why you say that "The elements are clickable inside the containing...
       · I'm new to CSS and found your article very helpful. I really like that I could...
       · Hello friend,After analyzing the topic, I ended up with the same conclusion. The...
       · Hello Paul,Thank you for the comments about the article. Regarding the example,...
       · I found Eric's demos of css menus to be a real help as well as this article.You...
       · ( Page 3 of 6 )I'm pretty sure there's a major typo on this page - surely the...
       · Hello friend,Thank you for pointing an excellent resource about the topic. It's...
       · Hi,Yes, You're correct. where it's specified z-index: 1; should read z-index:...
     

    STYLE SHEETS ARTICLES

    - Improving the Visual Presentation of a CSS D...
    - Fixing Browser Incompatibilities in a CSS Dr...
    - Building Clean Drop-Down Menus with CSS
    - Creating Hybrid Web Page Layouts with Negati...
    - Creating Three-Column Web Page Layous with N...
    - Swapping Column Positions in Web Page Layout...
    - Creating Web Page Layouts with Negative Marg...
    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT