Results 1 to 3 of 3

Thread: dynamic div-resizing

  1. #1
    Join Date
    Apr 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default dynamic div-resizing

    Does anyone know if it is possible to let a javascript dynamically change the size of a <div>-tag?

    example: I have a size that is designed for 1024*768... if the explorer window is in full size, the layout is good. When I change the size of the window or view the site at 800*600, a part of the site becomes invisible... is it possible to let Javascript calculate the new values for the position and size? if this is possible: is it also possible for <img> tags?

    bye,

    Bart

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yes but, not a good idea.
    Quote Originally Posted by Bart
    a part of the site becomes invisible...
    Don't you mean out of the view area but still visible using the scrollbar? Anyways (where's Mike when you need him?), using JavaScript for something like this will work except if the user has it turned off or unavailable. Even so, the complexity of the code required to cover all possible circumstance is very daunting, and if the user resizes the window or changes resolution after loading the page, more layers of code are required. It is far better to layout the page in a manner that looks OK in all resolutions and window sizes likely to be applied to it. Let text and other content wrap. Don't use HUGE images or divisions. Float content where appropriate. Use relative font sizes. Mike, are you listening?

    Note: References to Mike will be understood by anyone who frequents these forums. Understanding this message does not depend upon them.

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    Mike, are you listening?
    Yes. There isn't really much to add.

    HTML is inherently fluid; capable of adapting to viewport size automatically. If it doesn't, you've done something to stop it, such as using absolute widths in too many places. Clearly, there are places where specific widths are necessary, such as when working in concert with images, and navigation sidebars. However, the majority of your document should be capable of reflowing if necessary.

    Although fluidity would mean your page could spread across the entire viewport, you can prevent this happening using the max-width CSS property.

    Code:
    body {
      max-width: 40em;
    }
    Unfortunately, IE doesn't support this property, however you should be able to emulate it (but only in pixels):

    Code:
    body {
      /* Explicitly specify the margin so we know
       * what to subtract in the expression.
       */
      margin: 10px;
      padding: 0;
      max-width: 40em;
    }
    * html body {
      width: expression(Math.min(document.documentElement.clientWidth - 20, 600));
    }
    This will only work if the document is rendered in "Standards Mode". That is, you have a complete DOCTYPE specified for the document.

    Mike

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
  •