SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jan 2008
    Location
    Shaw AFB
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get the size of a div?

    I am wondering if it's possible to run a bit of Javascript to check the size of a div with an assigned class.

    For example - I'm running a vBulletin forum and users can't have a signature above 400px in height.

    So, when the page renders, I would like to run a javascript condition that checks to see if the height exceeds 400px. If so, add style="overflow:hidden; height:400px" to the div.
    ~ Nate L ~

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Why not just add that CSS to the DIV anyway, in the stylesheet, but use max-height? If it's below 400px, people will be none the wiser that overflow is hidden, so doing the JavaScript detection and adding that CSS would be redundant.

    IE6 doesn't support max-height, but you can use an expression (better if you have an IE76-only stylesheet, as this will render the code invalid).
    Code css:
    .signature {
      max-height:400px;
      overflow:hidden;
    }
    In ie6.css:
    Code css:
    .signature {
      height:expression(this.scrollHeight>399?"400px":"auto"); 
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •