Setting an Element's Visible Area (Clipping) Unlike setting the width and the height of an element, which controls the element's dimensions (see Chapter 6), clipping an absolute or fixed position element designates how much of that element's content will be visible (Table 8.2). The part that is not designated as visible will still be there, but viewers won't be able to see it, and the browser will treat it as empty space. Table 8.2. Clip ValuesVALUE | COMPATIBILITY |
---|
rect (<topLength> <rightLength><bottomLength> <leftLength>) | IE5[*], FF1, S1, O7, CSS2 | auto | IE4[*], FF1, S1, O7, CSS2 |
[*] IE5.5 for Windows In this example (Figure 8.3), the absolutely positioned drop box has been clipped so that only the cat's smiling face remains. Figure 8.3. The Cheshire Cat's face is all that appears from this image. The King, Queen, and Jack have all been clipped away. To define the clip area of an element: | | 1. | position: absolute; Set the position property to fixed or absolute (Code 8.2). Although clipping should work with other position types, Internet Explorer only recognizes it if the position is set to fixed or absolute.
Code 8.2. The clip region is defined for the dropBox class. | 2. | clip: Type the clip property name, followed by a colon (:).
| 3. | rect(15px 350px 195px 50px); Type rect to define the shape of the clip as a rectangle, an opening parenthesis ((), four values separated by spaces, a closing parenthesis ()), and a semicolon (;).
The numbers define the top, right, bottom, and left lengths of the clip area, respectively. All these values are distances from the element's origin (top-left corner), not from the indicated side(Figure 8.4).
Figure 8.4. The clipping region is defined by four values that detail how far from the origin the top, right, bottom, and left edges of the element's visible area should appear. Each value can be either a length value or auto, which allows the browser to determine the clip size (usually, 100 percent).
| Tips The element's borders and padding, but not its margin, will be clipped along with the content of the element. Currently, clips can be only rectangular, but future versions of CSS promise to support other shapes. You can change the clipping using DHTML (see "Changing an Object's Visible Area" in Chapter 16). |