SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    <div> Window Position

    Hi Everyone,

    How can I make a <div> element stay at the top of the window at all times. In other words, not the screen top, but the top of what the user sees. (even if they scroll halfway down the page.)

    Thanks.
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software

  2. #2
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fixed positioning via CSS (no JavaScript required) - note this will not work in IE6, but does work in IE7, which is now "final" and the current version:
    Code:
    div {
        position: fixed;
        top: 100px; /* change to suit your needs */
        left: 300px; /* change to suit your needs */
    }

  3. #3
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Schulz
    Fixed positioning via CSS (no JavaScript required) - note this will not work in IE6, but does work in IE7, which is now "final" and the current version:
    Code:
    div {
        position: fixed;
        top: 100px; /* change to suit your needs */
        left: 300px; /* change to suit your needs */
    }
    Thanks, that's great.
    My problem is just that most people won't be using IE7 too soon, I think.
    It's essential that it is cross browser compatible.

    I'm going to implement it, but I might need to change it later on. (if I find a better solution)
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software

  4. #4
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. I know of a nasty trick that uses absolute positioning to fake fixed positioning in IE 6 (it doesn't work in IE 5x though).

    http://www.cssplay.co.uk/layouts/fixed.html

  5. #5
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great link. Thanks, Dan


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
  •