Set an Element's Clipping
By Stephen Bucaro
Clipping defines the area of an element that will be visible. First set the position property of the
element to absolute. If you have a fixed webpage lay out, this should work fine. But if your webpage
elements need to follow normal "flow", you'll need to nest the clipped absolute positioned element
inside another element with position set to relative. This allows the clipped element into flow
into position when the webpage is rendered in the browser.
A clipping rectangle was applied to the span containing the flamingo image so that only the first flamingo is visible.
<span style="position:relative; top:0px; left:0px; width:90px; height:140px;">
<span style="position:absolute; top: 0px; left: 0px; clip:rect(30px 80px 150px 0px);">
<img alt="Famingos" border=0 width=180 height=160 src="flamingo_s.jpg"></span>
• Note that the order of values passed to the rect function is not the
standard left, top, right, bottom. Instead it's: top, right, bottom, left.
Even though you defined the containing element as position:relative, because of a bug in most
browsers, including Internet Explorer and Mozilla, elements after the span will not flow properly unless
you set a width and height for the containing element.
More CSS Quick Reference:
• Set a Background Image
• Set the Background Properties
• Style the First Line
• Set the Font Variant
• Set the Font Slant
• Use Inline Style
• Use an Embedded Style Sheet
• Set the Text Case
• Context selectors
• Set an Element's Padding