Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Horizontal Scrolling with absolute positioning inside relative positioning  (Read 8445 times)

0 Members and 1 Guest are viewing this topic.

colin

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Unknown
    Hi, I have a similar problem to with this example...

    http://dustyreagan.com/writing/1/example2.html

    When the page is shrunk horizontally, (but not so much as to cover the contents)
    it creates a horizontal scroller.
    If the red box is removed, this scroller is not seen.

    Anyway to get rid of the scroller until it is actually needed?

    Thanks

    kpac

    • Web moderator
    • Moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: Horizontal Scrolling with absolute positioning inside relative positioning
    « Reply #1 on: September 26, 2011, 10:50:20 AM »
    You're better off not using absolute positioning at all on a centered layout.

    colin

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Unknown
      Re: Horizontal Scrolling with absolute positioning inside relative positioning
      « Reply #2 on: September 26, 2011, 11:42:43 AM »
      Can you recommend anyway of replicating that page without absolute positioning?

      Thanks

      kpac

      • Web moderator
      • Moderator


      • Hacker

      • kpac®
      • Thanked: 184
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 7
      Re: Horizontal Scrolling with absolute positioning inside relative positioning
      « Reply #3 on: September 26, 2011, 11:57:27 AM »
      Where do you want to box to be exactly?

      colin

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Unknown
        Re: Horizontal Scrolling with absolute positioning inside relative positioning
        « Reply #4 on: September 26, 2011, 12:32:37 PM »
        Basically, a large box positioned centrally on the screen.

        Then I need images within it to be fixed at certain positions within it.
        So when the browser is stretched, the large box remains in the centre.

        I'm sure its possible, but I don't know how.

        Thanks for any help.

        kpac

        • Web moderator
        • Moderator


        • Hacker

        • kpac®
        • Thanked: 184
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 7
        Re: Horizontal Scrolling with absolute positioning inside relative positioning
        « Reply #5 on: September 26, 2011, 12:37:31 PM »
        I assume when you say "large box" you're talking about the red box? Or is it the #wrapper div?

        colin

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Unknown
          Re: Horizontal Scrolling with absolute positioning inside relative positioning
          « Reply #6 on: September 26, 2011, 12:56:37 PM »
          Yes, the large box is the #wrapper div.

          The small ones would be images, like the red box is, which I require to be at specific positions within the large box, such as (x,y), where (0,0) is the top left corner.

          kpac

          • Web moderator
          • Moderator


          • Hacker

          • kpac®
          • Thanked: 184
            • Yes
            • Yes
            • Yes
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 7
          Re: Horizontal Scrolling with absolute positioning inside relative positioning
          « Reply #7 on: September 26, 2011, 01:58:10 PM »
          Okay.

          This is the code which I'm wondering about:
          Code: [Select]
          <div style="position:relative;top:30px;left:200px">
          <img src="sample.gif" style="position:absolute" height="50" width="100" alt="our img" />

          Remove that <div> and just add the style it has directly to the image. Leave the "position:absolute" on the image, and forget about relative positioning for now - that might be affecting the parent <div>'s style.

          colin

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Unknown
            Re: Horizontal Scrolling with absolute positioning inside relative positioning
            « Reply #8 on: September 26, 2011, 02:11:29 PM »
            Thanks,

            Well if I do that...

            http://www.math.colin-java.co.uk/test.htm

            It half works, but I don't seem to be able to position the image at (x,y)
            If I try to, it just does it relative to the corner of the screen..

            Any thoughts?

            kpac

            • Web moderator
            • Moderator


            • Hacker

            • kpac®
            • Thanked: 184
              • Yes
              • Yes
              • Yes
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 7
            Re: Horizontal Scrolling with absolute positioning inside relative positioning
            « Reply #9 on: September 26, 2011, 02:39:52 PM »
            Yes, all you do now is set your "top:20px", "left:50px" etc. on the image. That should do it.

            colin

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Unknown
              Re: Horizontal Scrolling with absolute positioning inside relative positioning
              « Reply #10 on: September 26, 2011, 03:03:38 PM »
              It doesn't, it just puts it at the position relative to the top left corner of screen,
              which is of no use.

              It sort of works if I set it to relative, but then I can't get multiple images to show properly

              Rob Pomeroy



                Prodigy

              • Systems Architect
              • Thanked: 124
                • Me
              • Experience: Expert
              • OS: Other
              Re: Horizontal Scrolling with absolute positioning inside relative positioning
              « Reply #11 on: September 30, 2011, 08:06:41 AM »
              Absolute positioning is fine on a centred layout, providing the outer div/container has its position set to relative.  Then inner content can be set to absolute, but it's absolute relative to its parent container.  Yes I know it's counter-intuitive...
              Only able to visit the forums sporadically, sorry.

              Geek & Dummy - honest news, reviews and howtos