SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    div's style.width help

    I have 2 divs both hidden and absolute and sitting inside a relative div.

    Both divs (the absolote ones) are hidden until a javscript event triggers them to be displayed and alters their content. The second absolute div I want to sit flush on the right side of the first absolute div with top borders lined up. However in javascript when I do:
    document.getElementById("div_1").style.width or
    document.getElementById("div_1").style.right - nothing is returned, so I can not position the second div.

    I think this may be because the first div width is always different - depending on the contents it holds and doesn't have a defined style="width:###" attribute etc.

    Can somebody help, I am fairly new to divs and CSS.

  2. #2
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,692
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    If an element doesn't have a width, you can't fetch the width either.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  3. #3
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    makes sense...so if you want to have a div that changes size depending on the content what would be a way of going forward. Obviously you need to define a width programatically but how do you know what to define it so that the innerhtml content fits. if that makes sense

  4. #4
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,692
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't know, to be honest, but it doesn't seem very practical - for example, if the width takes up the entire screen width, then you'd have horisontal scrolling.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know in this case the width would never fall over 800 pixels etc..

    hmm hopefully there is a work around for such a situation.


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
  •