Results 1 to 8 of 8

Thread: position:relative; to a negatively positioned div?

  1. #1
    Join Date
    Dec 2006
    Beans
    795

    position:relative; to a negatively positioned div?

    Essentially, I am trying to place 5 items next to one another - all at a position of top:-20px; and left:10px; of the previous item.

    #item1 {position:absolute; top:-20px; left:10px;}
    #item2 {position:relative; top:0px; left:10px;}
    #item3 {position:relative; top:0px; left:20px;}
    #item4 {position:relative; top:0px; left:30px;}
    #item5 {position:relative; top:0px; left:40px;}

    The resulting layout is something similar to:
    Code:
    item1
              item2
                        item3
                                  item4
                                            item5
    Any suggestions on how to enjoy...
    Code:
    item1    item2    item3    item4    item5
    ...relatively?

    Thanks for any guidance!

  2. #2
    Join Date
    Jul 2011
    Location
    trapped between two traps
    Beans
    25
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: position:relative; to a negatively positioned div?

    Hm...could you use the negative size of item 1 instead the 0 px for top?
    Madness is ability for fine distinction between the different kinds of nonsense...Stan Ulam

  3. #3
    Join Date
    Jul 2011
    Location
    trapped between two traps
    Beans
    25
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: position:relative; to a negatively positioned div?

    Or put "bottom" instead of top? Trying to guess...
    Madness is ability for fine distinction between the different kinds of nonsense...Stan Ulam

  4. #4
    Join Date
    Aug 2009
    Beans
    296
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: position:relative; to a negatively positioned div?

    One thing that can matter is your header:

    <!DOCTYPE HTML>

    put that at the very top of your html document. It might help with css problems.


    For divs next to each other, make them use

    float:left;

    or

    float:right;

    while being

    position: relative;

  5. #5
    Join Date
    May 2011
    Location
    Bangor, Northern Ireland
    Beans
    19
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: position:relative; to a negatively positioned div?

    Yep, as Isaacgallegos mentioned, why not just float the items? Use a negative top margin, eg margin-top:-20px; to achieve the effect you want.

  6. #6
    Join Date
    Dec 2006
    Beans
    795

    Re: position:relative; to a negatively positioned div?

    Thanks, all, for your replies and suggestions.... After further review and trials and errors, your solution, Isaacgallegos turned out to be the winning one...

    Code:
    #item1,
    #item2,
    #item3,
    #item4,
    #item5,
    #item6 {position:relative; top:-20px; float:left; margin:10px;}
    ...with the items' order in the html (1,2,3... vs. 6,5,4...) determining their ultimate order in the browser....

    Thanks for the guidance!

  7. #7
    Join Date
    Aug 2009
    Beans
    296
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: position:relative; to a negatively positioned div?

    Cool. If it dosen't work across different browsers, you might need to paste <!DOCTYPE HTML> at the very top or a different doctype.

  8. #8
    Join Date
    Dec 2006
    Beans
    795

    Re: position:relative; to a negatively positioned div?

    Yep - doctype is:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    Thanks, again, for the comments!

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
  •