clip style property
Specifies or returns which part of a positioned element is visible.
A positioned element is an element whose position property is set to relative, absolute or fixed.
This property only works for absolute or fixed positioned elements.
You can set the top, right, bottom, and left coordinates of the visible region with this property, relative to the upper-left corner of the element.
- The value of top defines a line, content above this line will be hidden.
- The value of bottom defines a line, content below this line will be hidden.
- The value of left defines a line, content left of this line will be hidden.
- The value of right defines a line, content right of this line will be hidden.
If you want to clear the clip settings, use the Rect(auto auto auto auto) value in Internet Explorer and the auto value in other browsers.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: clip |
Possible values:
The type of this property is string.
One of the following values:
Default. The element does not clip. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
Clips the shape defined by the four coordinates (top right bottom left). |
Default: auto.
Example HTML code 1:
This example illustrates the use of the clip property:
|
||||
<head> <style> .notclipped { position: absolute; top: 260px; left: 260px; width: 100px; height: 100px; border: 2px solid black; } .clipped { position: absolute; top: 260px; left: 260px; width: 100px; height: 100px; background-color: red; clip: rect(20px 70px 60px 10px); } </style> </head> <body> The black border represents a rectangle with size width and height of 100px. <br /> The red rectangle has size width and height of 100px too, with 'clip: rect(20px 70px 60px 10px)'. <br /> It means: <ul> <li>hide the area above the line 20px from top</li> <li>hide the area right form the line 70px from left</li> <li>hide the area below the line 60px from top</li> <li>hide the area left from the line 10px from left</li> </ul> <div class="notclipped"></div> <div class="clipped"></div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the clip property in JavaScript:
|
||||
<head> <style> .example { position: absolute; top: 80px; left: 80px; clip: rect(10px 40px 40px 10px); } </style> <script type="text/javascript"> function ChangeClip (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the text of the selected option var selectState = selectTag.options[whichSelected].text; var image = document.getElementById ("myImage"); image.style.clip = selectState; } </script> </head> <body> <img class="example" id="myImage" src="picture.gif"> <!-- The red rectangle, only necessary for the example --> <div style="border:1px solid red; position:absolute;top:80px; left:80px; width:48px; height:48px;"></div> <select onchange="ChangeClip (this);" size="6" style="margin-top: 140px"> <option selected="selected" />rect(10px 40px 40px 10px) <option />rect(auto auto auto auto) <option />rect(20px 40px 40px 10px) <option />rect(10px 20px 40px 10px) <option />rect(10px 40px 20px 10px) <option />rect(10px 40px 40px 20px) </select> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, applet, b, bdo, big, blink, blockquote, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, h1, h2, h3, h4, h5, h6, hr, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, object, ol, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, td, textarea, th, tr, tt, u, ul, var, xmp
Related pages:
External links:
User Contributed Comments