CSS Reference

"overflow" - css property (v. css 2)

  • To specify what happens if content overflows the box of an element
  • Initial value: visible
  • The property is not inherited
  • HTML usage: non-replaced block-level elements, table cells, inline-table, and inline-block elements
  • Browsers that support the overflow - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari

Possible overflow values:

overflow value Comments CSS
visible Indicates that content is not clipped, i.e., it may be rendered outside the block box. 2
Indicates that the content is clipped and that no scrolling user interface should be provided to view the content outside the clipping region. 2
scroll Indicates that the content is clipped and uses a scrolling mechanism that is visible on the screen (such as a scroll bar or a panner), that mechanism should be displayed for a box whether or not any of its content is clipped. 2
auto The behavior of this value is user agent-dependent, but should cause a scrolling mechanism to be provided for overflowing boxes. 2
inherit Will inherit the value from parent specification. 2

Property "overflow" example:

<!DOCTYPE HTML >
<html>
  <head>
    <script type="text/javascript">
      function changeOverflow(value) {
        document.getElementById("p1").style.overflow=value;
      }
    </script>
    <style   type="text/css">
      #p1 { width: 190px; height: 80px;
      }
    </style>
  </head>
  <body >
    <h1 >CSS Selectors</h1>
    <p id="p1">One of the primary advantages of
      CSSparticularly to designersis its ability to
      easily apply a set of styles to all elements
      of the same type. Unimpressed? Consider this:
      by editing a single line of CSS, you can change
      the colors of all your headings.</p>
    <br/><br/><br/>
    <div>
      <input type="button" onclick="changeOverflow('hidden')"
             value="Paragraph to overflow: hidden" /><br/>
      <input type="button" onclick="changeOverflow('visible')"
             value="Paragraph to overflow: visible" /><br/>
      <input type="button" onclick="changeOverflow('auto')"
             value="Paragraph to overflow: auto" /><br/>
      <input type="button" onclick="changeOverflow('scroll')"
             value="Paragraph to overflow: scroll" /><br/>
    </div>
  </body>
</html>

Javascript access:

// To SET values ([o] is the target object)
[o].style.overflow="overflow value"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:;
var value=cStyle.overflow;
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.