Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Cross Browser Issues
Expertise: Beginner
Sep 7, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Modify the CSS Clip Property in a DIV

How can I change the values of the Cascading Style Sheets (CSS) clip property after the DIV is created?


For the current releases of Navigator and IE (IE 4.x/5.x and Navigator 4.x), altering the CSS clip property of a DIV block once the page is rendered will require handling some special cross-browser differences. First of all, the DIV block will need to be absolutely positioned for the dynamic clipping to work with both Navigator and IE. In addition, you'll most likely want to provide a preliminary clipping area, though this isn't required:


To perform the clipping, you will need to check for the type of browser before modifying the CSS clipping values. In this code, I use the object model to test for browser type primarily because of the brevity of the code for this approach; you will want to use your own favorite approach:

   if (document.all)
      temp.style.clip="rect(0 400 400 0)";
   else if (document.layers) {

The "document.all" condition succeeds for IE 4.x and IE 5.x and as the clipping value is modified by changing the entire clipping rectangle at once.

The second browser check, testing for "document.layers", will succeed for Navigator 4.x and the code for this browser sets the right and bottom sides of the clipping rectangle individually.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date