Style Sheets
  Home arrow Style Sheets arrow Page 5 - 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 - The "overflow" property


    (Page 5 of 6 )

    This property defines how the element treats content that exceeds the specified widths or heights applied to it. The default behavior for all elements is to respect the width property and let the overflowed content flow down in the element, thus varying the height according to the total length of the content. The following values may be set for this property:

    overflow: visible;

    The selected block element will expand accordingly, in order to display the full width and height of contents. Padding and margin values applied to the element are preserved.

    overflow: hidden;

    The selected block element is forced to preserve its width and height properties, potentially clipping the overflowed content by the size of the element. Borders and padding values are preserved, but margin values might be removed along the edges that clip the content. No scrollbars are displayed with this value.

    overflow: scroll;

    The selected block element will show a set of scrollbars inside the element, regardless of whether or not they're needed. The scrollbars are activated only if the size if the content requires scrolling in any direction.

    overflow: auto;

    The selected block element will generate scrollbars only if the content exceeds the size of the element.

    Here are several examples to demonstrate the use of this property:

    <style type="text/css">

    #element1 {

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

         color: #000;

         position: absolute;

         top: 20px;

         left: 10px;

         width: 30px;

         background: #fc0;

         padding: 10px;

         overflow: auto;

    }

    </style>

    The HTML markup is the following:

    <div id="element1">Element content goes here............and more content is placed here.</div>

    In this case, we've assigned the value "auto" to the "overflow" property. Since the content included into the element exceeds the width of the container, it will display a set of scrollbars, as illustrated below:

    Now, let's see what happens when we modify the content's length in a way that doesn't exceed the width of the container element. The CSS code is the same:

    <style type="text/css">

    #element1 {

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

         color: #000;

         position: absolute;

         top: 20px;

         left: 10px;

         width: 30px;

         background: #fc0;

         padding: 10px;

         overflow: auto;

    }

    </style>

    But the content within the markup has been significantly reduced to this:

    <div id="element1">Element 1 content</div>

    The visual output would be as follows:

    Clearly, we can appreciate that the set of scrollbars is not present, since the content now fits seamlessly into the container element.

    Let's implement the same above code, but this time specifying a value of "visible":

    <style type="text/css">

    #element1 {

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

         color: #000;

         position: absolute;

         top: 20px;

         left: 10px;

         width: 30px;

         background: #fc0;

         padding: 10px;

         overflow: visible;

    }

    </style>

    With the same HTML markup:

    <div id="element1">Element content goes here............and more content is placed here.</div>

    The visual output is showed below:

    This time, the container element expands its width accordingly, in order to display the full width and height of contents, as perceived in the image.

    Finally, let's assign the values of "hidden" and "scroll" to the property and see how the visual output is rendered.

    This is the visual output with a value of "hidden" assigned to the property. We can see that the content is partially clipped from the container element. Similarly, here's the output when a value of "scroll" is specified:

    Now, the container element shows a set of scrollbars around, for scrolling the content either horizontally or vertically. In this particular case, the content will scroll horizontally. Vertical scrollbars are disabled.

    So far, we've illustrated with examples the different behaviors for each value assigned to the "overflow" property. It's valid to mention that NS 4 does not support this property, so if you're still getting visitors using this old browser, its implementation should be avoided.

    Finally, we're going to demonstrate a simple but useful example to create drop-down menus using the "overflow" and "display" property, as a follow-up for this guide. Let's put our coder abilities into action.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · 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 4 hosted by Hostway
    Stay green...Green IT