relative/absolute positioning

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wim Roffal

    #1

    relative/absolute positioning

    I am trying to create a menu system.

    The mainmenu is a table
    <table><tr><td> menu1</td><td>menu2</td></tr></table>

    No I try insert the submenu so that it becomes relative to the main menu
    item. For menu1 the relevant code then becomes:

    <td style="position :relative;">men u1<div style="position :absolute; top:20;
    left:0;">
    <a href=x.htm>opti on1</a><br>
    <a href=y.htm>opti on2</a>
    </div></td>

    This works fine in IE: the div is positioned relative to the td of menu1.
    However, in Mozilla it doesn't work. The div becomes relative to the top of
    the page.

    What am I doing wrong?

    Thanks,

    Wim


  • Evertjan.

    #2
    Re: relative/absolute positioning

    Wim Roffal wrote on 08 sep 2004 in comp.lang.javas cript:
    [color=blue]
    > I am trying to create a menu system.
    >
    > The mainmenu is a table
    > <table><tr><td> menu1</td><td>menu2</td></tr></table>
    >
    > No I try insert the submenu so that it becomes relative to the main
    > menu item. For menu1 the relevant code then becomes:
    >
    > <td style="position :relative;">men u1<div style="position :absolute;
    > top:20; left:0;">
    > <a href=x.htm>opti on1</a><br>
    > <a href=y.htm>opti on2</a>
    > </div></td>
    >
    > This works fine in IE: the div is positioned relative to the td of
    > menu1. However, in Mozilla it doesn't work. The div becomes relative
    > to the top of the page.
    >
    > What am I doing wrong?[/color]

    What you are doing wrong is asking this in a javascript NG.

    There is no script to be seen and
    for css style there is a NG called:

    comp.infosystem s.www.authoring.stylesheets

    [a strange name for this group, I admit]


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)

    Comment

    • kaeli

      #3
      OT: CSS (was Re: relative/absolute positioning)

      In article <chn69v$379$1@r eader11.wxs.nl> , wimroffelplease @nospamm-planet.nl
      enlightened us with...[color=blue]
      >
      > <td style="position :relative;">men u1<div style="position :absolute; top:20;
      > left:0;">
      > <a href=x.htm>opti on1</a><br>
      > <a href=y.htm>opti on2</a>
      > </div></td>
      >
      > This works fine in IE: the div is positioned relative to the td of menu1.[/color]

      Then IE is wrong. You're probably using quirks mode by not providing a valid
      doctype with a URL.
      Absolute is absolute.
      [color=blue]
      > However, in Mozilla it doesn't work. The div becomes relative to the top of
      > the page.
      >[/color]

      As it should be.
      [color=blue]
      > What am I doing wrong?
      >[/color]

      Posting a CSS question to a javascript group. ;)

      Put this at the top of the page, save it, then look in IE again. What
      happened?
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">

      See
      http://msdn.microsoft.com/workshop/a...ts/doctype.asp

      See the group mentioned by Evertjan as well for additional CSS help.

      --
      --
      ~kaeli~
      Reading while sunbathing makes you well red.



      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: OT: CSS

        kaeli <tiny_one@NOSPA M.comcast.net> writes:
        [color=blue]
        > In article <chn69v$379$1@r eader11.wxs.nl> , wimroffelplease @nospamm-planet.nl
        > enlightened us with...[color=green]
        >>
        >> <td style="position :relative;">men u1<div style="position :absolute; top:20;
        >> left:0;">[/color][/color]
        [color=blue][color=green]
        >> This works fine in IE: the div is positioned relative to the td of menu1.[/color]
        >
        > Then IE is wrong. You're probably using quirks mode by not providing a valid
        > doctype with a URL.
        > Absolute is absolute.[/color]

        Actually, "position:absol ute" must position relative to its containing
        block, which is the nearest enclosing positioned block-level element,
        if any. That is why it is not relative to the "td" (it is not a block level
        element).
        <URL:http://www.w3.org/TR/CSS2/visuren.html#ab solute-positioning>
        <URL:http://www.w3.org/TR/CSS2/visuren.html#q2 9>
        <URL:http://www.w3.org/TR/CSS2/visudet.html#co ntaining-block-details>

        The problem is that the "td" has "display:ta ble-cell" and not
        "display-block".

        Anyway, the "top:20" is also wrong, and should be "top:20px". That
        means that the y-position of the div is not changed from its default,
        which might be why it *seems* to be positionened correctly anyway.
        [color=blue][color=green]
        >> However, in Mozilla it doesn't work. The div becomes relative to the top of
        >> the page.[/color][/color]

        Ditto in Opera. If I add "display:bl ock" to the "td", then the "div"
        does become positioned wrt. the "td", because it is now a positioned
        block-level element, so it becomes the containing block of the "div".
        [color=blue]
        > As it should be.[/color]

        Actually, yes, but the reasons for that are not obvious :)
        [color=blue]
        > Put this at the top of the page, save it, then look in IE again. What
        > happened?
        > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
        > "http://www.w3.org/TR/html4/loose.dtd">[/color]

        I concur, and fix the bugs in the CSS. Then perhaps wrap the
        "div" in another, relatively positioned, "div" inside the "td".

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Michael Winter

          #5
          Re: OT: CSS

          On Wed, 08 Sep 2004 18:51:43 +0200, Lasse Reichstein Nielsen
          <lrn@hotpop.com > wrote:

          [snip]
          [color=blue]
          > Then perhaps wrap the "div" in another, relatively positioned, "div"
          > inside the "td".[/color]

          As this is for a menu, wouldn't something more semantically appropriate
          than a table and nested DIVs be better, such as the commonly used list? It
          would certainly involve less mark-up.

          Mike

          --
          Michael Winter
          Replace ".invalid" with ".uk" to reply by e-mail.

          Comment

          • Grant Wagner

            #6
            Re: relative/absolute positioning

            Wim Roffal wrote:
            [color=blue]
            > <td style="position :relative;">men u1<div style="position :absolute; top:20;
            > left:0;">
            > <a href=x.htm>opti on1</a><br>
            > <a href=y.htm>opti on2</a>
            > </div></td>
            >
            > This works fine in IE: the div is positioned relative to the td of menu1.
            > However, in Mozilla it doesn't work. The div becomes relative to the top of
            > the page.
            >
            > What am I doing wrong?[/color]

            You're asking a CSS question in a JavaScript newsgroup.

            --
            Grant Wagner <gwagner@agrico reunited.com>
            comp.lang.javas cript FAQ - http://jibbering.com/faq

            Comment

            • kaeli

              #7
              Re: OT: CSS

              In article <eklcln4w.fsf@h otpop.com>, lrn@hotpop.com enlightened us with...[color=blue][color=green]
              >>[/color]
              > Actually, "position:absol ute" must position relative to its containing
              > block, which is the nearest enclosing positioned block-level element,
              > if any. That is why it is not relative to the "td" (it is not a block level
              > element).[/color]
              [color=blue]
              > <URL:http://www.w3.org/TR/CSS2/visuren.html#ab solute-positioning>[/color]

              Ah, I was looking for that and couldn't find it. All the sites I was hitting
              with Google search said it was indeed absolute. Of course, I was looking in
              CSS1 like a moron.
              Hrmph.

              Well, at least I know if I say something dumb, someone will correct me.
              Thanks. :)


              --
              --
              ~kaeli~
              Black holes were created when God divided by 0.



              Comment

              • Wim Roffal

                #8
                Re: OT: CSS


                "Michael Winter" <M.Winter@bluey onder.co.invali d> schreef in bericht
                news:opsd0p6fcg x13kvk@atlantis ...[color=blue]
                > On Wed, 08 Sep 2004 18:51:43 +0200, Lasse Reichstein Nielsen
                > <lrn@hotpop.com > wrote:
                >
                > [snip]
                >[color=green]
                > > Then perhaps wrap the "div" in another, relatively positioned, "div"
                > > inside the "td".[/color]
                >
                > As this is for a menu, wouldn't something more semantically appropriate
                > than a table and nested DIVs be better, such as the commonly used list? It
                > would certainly involve less mark-up.[/color]

                Can you give an example of what you mean?

                Wim



                Comment

                • Andrew Thompson

                  #9
                  Re: OT: CSS

                  On Wed, 8 Sep 2004 20:50:49 +0200, Wim Roffal wrote:
                  [color=blue]
                  > "Michael Winter" <M.Winter@bluey onder.co.invali d> schreef in bericht[/color]
                  [color=blue][color=green]
                  >> As this is for a menu, wouldn't something more semantically appropriate
                  >> than a table and nested DIVs be better, such as the commonly used list? It
                  >> would certainly involve less mark-up.[/color]
                  >
                  > Can you give an example of what you mean?[/color]

                  I am not sure if this is a *good* example,
                  but the menu down the left of my site is
                  a styled list.. <http://www.physci.org/codes/>

                  Often web-designers would mark that up as a table.

                  --
                  Andrew Thompson
                  http://www.PhySci.org/ Open-source software suite
                  http://www.PhySci.org/codes/ Web & IT Help
                  http://www.1point1C.org/ Science & Technology

                  Comment

                  • Andrew Urquhart

                    #10
                    Re: OT: CSS

                    *Andrew Thompson* wrote in comp.lang.javas cript:[color=blue]
                    > On Wed, 8 Sep 2004 20:50:49 +0200, Wim Roffal wrote:
                    >[color=green]
                    >> "Michael Winter" <M.Winter@bluey onder.co.invali d> schreef in bericht[/color]
                    >[color=green][color=darkred]
                    >>> As this is for a menu, wouldn't something more semantically appropriate
                    >>> than a table and nested DIVs be better, such as the commonly used list? It
                    >>> would certainly involve less mark-up.[/color]
                    >>
                    >> Can you give an example of what you mean?[/color]
                    >
                    > I am not sure if this is a *good* example,
                    > but the menu down the left of my site is
                    > a styled list.. <http://www.physci.org/codes/>
                    >
                    > Often web-designers would mark that up as a table.[/color]

                    This page is unstyled for me in Opera 7.51 Win2K!

                    http://accessibletoall.com/au/pix/mi..._org_codes.png [52KB]
                    --
                    Andrew Urquhart
                    - FAQ: http://www.jibbering.com/faq/
                    - Archive: http://www.google.com/groups?q=comp.lang.javascript
                    - Contact me: http://andrewu.co.uk/contact/

                    Comment

                    • Michael Winter

                      #11
                      Re: OT: CSS

                      On Wed, 8 Sep 2004 20:50:49 +0200, Wim Roffal
                      <wimroffelpleas e@nospamm-planet.nl> wrote:
                      [color=blue]
                      > "Michael Winter" <M.Winter@bluey onder.co.invali d> schreef in bericht
                      > news:opsd0p6fcg x13kvk@atlantis ...
                      >[color=green]
                      >> On Wed, 08 Sep 2004 18:51:43 +0200, Lasse Reichstein Nielsen
                      >> <lrn@hotpop.com > wrote:
                      >>
                      >> [snip]
                      >>[color=darkred]
                      >>> Then perhaps wrap the "div" in another, relatively positioned, "div"
                      >>> inside the "td".[/color]
                      >>
                      >> As this is for a menu, wouldn't something more semantically appropriate
                      >> than a table and nested DIVs be better, such as the commonly used
                      >> list? It would certainly involve less mark-up.[/color]
                      >
                      > Can you give an example of what you mean?[/color]

                      Well first, exactly what kind of menu are you trying to produce. By the
                      looks of things, it's a drop-down, application-like menu. If that's the
                      case, take a look at:

                      <URL:http://devedge.netscap e.com/viewsource/2003/devedge-redesign-js/>

                      and the two links in the Conclusion. None of them are perfect, but they're
                      far better than most horizontal menus in widespread use. If it's a
                      vertical menu, take Andrew's link. If it's none of the above, you'd best
                      state your aims clearly.

                      As for the semantics, stuffing a series of DIVs inside a TABLE element
                      doesn't make a lot of sense from a structural point of view.

                      Mike

                      --
                      Michael Winter
                      Replace ".invalid" with ".uk" to reply by e-mail.

                      Comment

                      • Andrew Thompson

                        #12
                        Re: OT: CSS

                        On Wed, 08 Sep 2004 19:41:29 GMT, Andrew Urquhart wrote:

                        (A.T.)[color=blue][color=green]
                        >> I am not sure if this is a *good* example,
                        >> but the menu down the left of my site is
                        >> a styled list.. <http://www.physci.org/codes/>[/color][/color]
                        ...[color=blue]
                        > This page is unstyled for me in Opera 7.51 Win2K!
                        >
                        > http://accessibletoall.com/au/pix/mi..._org_codes.png[/color]

                        Huh! Go figure.. It renders as I
                        expect, using Opera 7.54 on Win XP.

                        I do notice that the in-line styles are
                        rendered (the 'Home' link), could be a
                        a) a content-negotiation thing, or..
                        b) kludgy release of Opera, but I put odds on..
                        c) the server got a bit sleepy during the
                        download and did not deliver the stylesheet.

                        Could you refresh the page later and
                        see if it comes good?

                        ...errr you, ..haven't overidden the
                        site style-sheet with a user stylesheet
                        by any chance, have you?

                        [ Thanks for the screen-shot BTW, a
                        picture paints a thousand words. ]

                        --
                        Andrew Thompson
                        http://www.PhySci.org/ Open-source software suite
                        http://www.PhySci.org/codes/ Web & IT Help
                        http://www.1point1C.org/ Science & Technology

                        Comment

                        • Andrew Thompson

                          #13
                          Re: OT: CSS

                          On Wed, 08 Sep 2004 20:15:54 GMT, Andrew Thompson wrote:
                          [color=blue]
                          > c) the server got a bit sleepy during the
                          > download and did not deliver the stylesheet.
                          >
                          > Could you refresh the page later and
                          > see if it comes good?[/color]

                          Now I look more closely at the screen-grab,
                          I'm even more sure that's it. One of the
                          images is missing as well.

                          --
                          Andrew Thompson
                          http://www.PhySci.org/ Open-source software suite
                          http://www.PhySci.org/codes/ Web & IT Help
                          http://www.1point1C.org/ Science & Technology

                          Comment

                          • Andrew Urquhart

                            #14
                            Re: OT: CSS

                            *Andrew Thompson* wrote in comp.lang.javas cript:[color=blue]
                            > I do notice that the in-line styles are rendered (the 'Home' link),
                            > could be a a) a content-negotiation thing, or.. b) kludgy release of
                            > Opera, but I put odds on.. c) the server got a bit sleepy during the
                            > download and did not deliver the stylesheet.
                            >
                            > Could you refresh the page later and see if it comes good?[/color]

                            Oh dear, yes it has! Earlier I tried several hard-refreshes before I
                            decided to mention it.
                            [color=blue]
                            > ..errr you, ..haven't overidden the site style-sheet with a user
                            > stylesheet by any chance, have you?[/color]

                            The screenshot shows that the browser is in 'author mode'.
                            [color=blue]
                            > [Thanks for the screen-shot BTW, a picture paints a thousand words.][/color]

                            OK, I'll delete it in a moment now that it's finished with.
                            --
                            Andrew Urquhart
                            - FAQ: http://www.jibbering.com/faq/
                            - Archive: http://www.google.com/groups?q=comp.lang.javascript
                            - Contact me: http://andrewu.co.uk/contact/

                            Comment

                            • Andrew Thompson

                              #15
                              Re: OT: CSS

                              On Wed, 08 Sep 2004 20:43:33 GMT, Andrew Urquhart wrote:
                              [color=blue][color=green]
                              >> Could you refresh the page later and see if it comes good?[/color]
                              >
                              > Oh dear, yes it has! Earlier I tried several hard-refreshes before I
                              > decided to mention it.[/color]

                              The server must be having some real
                              problems, it must have been very
                              hard pressed, I better look into it.
                              [color=blue][color=green]
                              >> ..errr you, ..haven't overidden the site style-sheet with a user
                              >> stylesheet by any chance, have you?[/color]
                              >
                              > The screenshot shows that the browser is in 'author mode'.[/color]

                              Oops, ..sorry! ( It was the thousand and
                              *oneth* word that would have got that
                              through my thick skull ;-)

                              Thanks again.

                              --
                              Andrew Thompson
                              http://www.PhySci.org/ Open-source software suite
                              http://www.PhySci.org/codes/ Web & IT Help
                              http://www.1point1C.org/ Science & Technology

                              Comment

                              Working...