CSS Reference

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

  • A clipping region defines what portion of an element's border box is visible.
  • By default, the element is not clipped.
  • However, the clipping region may be explicitly set with this 'clip' property.
  • Initial value: auto
  • The property is not inherited
  • HTML usage: absolutely positioned elements
  • To clip an element: you must specify the position to absolute or fixed.
  • Browsers that support the clip - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari

Illustrates a property clip value

Possible clip values:

Values Comments CSS
auto The element does not clip. 2
rect(top,right,bottom,left) Defining a clipping region. 2
top length With this you specify a positive(+) or negative(-) value followed with a unit identifier from the top for top edge of the rectangle region to clip. 2
auto Means the same as top='0px' 2
right length With this you specify a positive(+) or negative(-) value followed with a unit identifier from the left for right edge of the rectangle region to clip. 2
auto Means the same as right='0px' 2
bottom length With this you specify a positive(+) or negative(-) value followed with a unit identifierfrom the top for bottom edge of the rectangle region to clip. 2
auto Means the same as bottom='0px' 2
left length With this you specify a positive(+) or negative(-) value followed with a unit identifier from the left for left edge of the rectangle region to clip. 2
auto Means the same as left='0px' 2
inherit Will inherit the value from parent specification. 2

Possible unit identifier:

unit identifier Comments CSS
em The relative unit 'em' is relative to the font size of the element itself. 1
ex The relative unit 'ex' is relative to the font size of the element itself. 1
px Pixels, relative to the viewing device 1
in inches -> 1 inch is equal to 2.54 centimeters. 1
cm centimeters. 1
mm millimeters. 1
pt points -> the points used by CSS2 are equal to 1/72th of an inch. 1
pc picas -> 1 pica is equal to 12 points. 1

Property "clip" example:

<!DOCTYPE HTML >
<html  >
  <head>
    <title>Test</title>
    <script type="text/javascript" >
    </script>
    <style   type="text/css">
      .clip1 { position: absolute;
               clip: rect(0px, 139px, 50px, 55px);
               left: -50px;
      }

    </style>
  </head>
  <body >
    <img src="images/Sun.gif" border="0" alt=""/>
    <br/><br/>
    clip: rect(0px, 139px, 50px, 55px)<br/>
    and moved -50px in x-direction;
    <div class="clip1" >
      <img src="images/Sun.gif"
           border="0" alt=""/>
    </div>
  </body>
</html>

Javascript access:

// To SET values ([o] is the target object)
[o].style.clip="clip 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.clip;
/* The returned value is not cross-browser reliable. The value can vary in accuracy and notation, which depends on the browser, whether the value is preset or not and which option that was used to set the value.*/
© 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.