how to layout forms with css

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

    how to layout forms with css

    Hi,

    Since the good support of CSS we shouldn't use tables for layout. And I
    am quite far in using divs and styling elements to position them without
    the use of tables.
    I was wondering how we could layout forms without tables so we would
    have each input text field below each other.

    for example:
    NAME: INPUT FIELD
    PASSWORD: INPUT FIELD

    Any suggestions?

    --
    Web development en webhosting

    webdesign, internet applicaties, internetgestuur de elektronica
  • Harlan Messinger

    #2
    Re: how to layout forms with css


    "Roderik" <mail@roderik.n et> wrote in message
    news:412cfe13$0 $62368$5fc3050@ dreader2.news.t iscali.nl...[color=blue]
    > Hi,
    >
    > Since the good support of CSS we shouldn't use tables for layout. And I
    > am quite far in using divs and styling elements to position them without
    > the use of tables.
    > I was wondering how we could layout forms without tables so we would
    > have each input text field below each other.
    >
    > for example:
    > NAME: INPUT FIELD
    > PASSWORD: INPUT FIELD[/color]

    I'm of the camp that says that this is a tabular arrangement: labels in one
    column, user input in another. So go ahead a use a table if you want.

    Otherwise, float the labels to the left using CSS. (Code below is untested.)

    label { float: left; width: 20em; padding-right: 1em; }
    ....
    <div><label for="userName"> User name:</label><input type="text"
    name="userName" value=""></div>
    ....

    Comment

    • Neal

      #3
      Re: how to layout forms with css

      On Wed, 25 Aug 2004 23:01:06 +0200, Roderik <mail@roderik.n et> wrote:
      [color=blue]
      > Hi,
      >
      > Since the good support of CSS we shouldn't use tables for layout. And I
      > am quite far in using divs and styling elements to position them without
      > the use of tables.
      > I was wondering how we could layout forms without tables so we would
      > have each input text field below each other.
      >
      > for example:
      > NAME: INPUT FIELD
      > PASSWORD: INPUT FIELD
      >
      > Any suggestions?[/color]

      No CSS needed to do this.

      <div><label for="realname"> Your Name (required):</label><input type="text"
      name="realname" id="realname"> </div>
      <div><label for="email">Ema il Address (required):</label><input
      type="text" name="email" id="email"></div>

      If you want to put the input field over to a specific spot, try this CSS
      on the above HTML.

      form div {position: relative;}
      form div label {width: 12em;}
      form div input {position: absolute; left: 13em;}

      Comment

      • Neal

        #4
        Re: how to layout forms with css

        On Wed, 25 Aug 2004 17:17:27 -0400, Harlan Messinger
        <h.messinger@co mcast.net> wrote:

        [color=blue][color=green]
        >> NAME: INPUT FIELD
        >> PASSWORD: INPUT FIELD[/color]
        >
        > I'm of the camp that says that this is a tabular arrangement: labels in
        > one
        > column, user input in another.[/color]

        But isn't the purpose of a table to offer a comparison amongst the data? I
        think a table needs columns and rows which compare similar data, but this
        isn't for that purpose really.

        Of course, I won't shoot you.

        Comment

        • Els

          #5
          Re: how to layout forms with css

          Neal wrote:

          [form layout]
          [color=blue]
          > No CSS needed to do this.
          >
          > <div><label for="realname"> Your Name
          > (required):</label><input type="text" name="realname"
          > id="realname"> </div> <div><label for="email">Ema il Address
          > (required):</label><input type="text" name="email"
          > id="email"></div>
          >
          > If you want to put the input field over to a specific spot,
          > try this CSS on the above HTML.
          >
          > form div {position: relative;}
          > form div label {width: 12em;}
          > form div input {position: absolute; left: 13em;}[/color]

          Here's me thinking: "this sounds so easy, but I'm sure it was a
          heck of a lot more complicated when I tried it once" ...
          Then I realised that was cause I wanted the labels right
          aligned... :-)

          --
          Els
          Blog and other pages, mostly outdated.

          Sonhos vem. Sonhos vão. O resto é imperfeito.
          - Renato Russo -

          Comment

          • Neal

            #6
            Re: how to layout forms with css

            On 25 Aug 2004 21:38:47 GMT, Els <els.aNOSPAM@ti scali.nl> wrote:
            [color=blue]
            > Neal wrote:
            >
            > [form layout]
            >[color=green]
            >> No CSS needed to do this.
            >>
            >> <div><label for="realname"> Your Name
            >> (required):</label><input type="text" name="realname"
            >> id="realname"> </div> <div><label for="email">Ema il Address
            >> (required):</label><input type="text" name="email"
            >> id="email"></div>
            >>
            >> If you want to put the input field over to a specific spot,
            >> try this CSS on the above HTML.
            >>
            >> form div {position: relative;}
            >> form div label {width: 12em;}
            >> form div input {position: absolute; left: 13em;}[/color]
            >
            > Here's me thinking: "this sounds so easy, but I'm sure it was a
            > heck of a lot more complicated when I tried it once" ...
            > Then I realised that was cause I wanted the labels right
            > aligned... :-)
            >[/color]

            form div {position: relative;}
            form div label {display: block; width: 10em; text-align: right;}
            form div input {position: absolute; top: 0; left: 13em;}

            Works in Opera and IE.

            Comment

            • Neal

              #7
              Re: how to layout forms with css

              On Wed, 25 Aug 2004 17:44:13 -0400, Neal <neal413@yahoo. com> wrote:
              [color=blue]
              > On 25 Aug 2004 21:38:47 GMT, Els <els.aNOSPAM@ti scali.nl> wrote:[color=green]
              >> Here's me thinking: "this sounds so easy, but I'm sure it was a
              >> heck of a lot more complicated when I tried it once" ...
              >> Then I realised that was cause I wanted the labels right
              >> aligned... :-)
              >>[/color]
              >
              > form div {position: relative;}
              > form div label {display: block; width: 10em; text-align: right;}
              > form div input {position: absolute; top: 0; left: 13em;}
              >
              > Works in Opera and IE.[/color]

              Until you change text size in IE, dammit.

              This fixes that.

              form div {position: relative; font-size: 100%;}
              form div label {display: block; width: 10em; text-align: right;}
              form div input {font-size: 100%; position: absolute; top: 0; left: 13em;}

              Comment

              • kchayka

                #8
                Re: how to layout forms with css

                Neal wrote:
                [color=blue]
                > On Wed, 25 Aug 2004 17:17:27 -0400, Harlan Messinger
                > <h.messinger@co mcast.net> wrote:
                >[color=green][color=darkred]
                >>> NAME: INPUT FIELD
                >>> PASSWORD: INPUT FIELD[/color]
                >>
                >> I'm of the camp that says that this is a tabular arrangement: labels in
                >> one column, user input in another.[/color]
                >
                > But isn't the purpose of a table to offer a comparison amongst the data?[/color]

                I believe it's more intended to show a relationship between data in
                associated cells, which is not the same thing. In this case, the left
                column might even be considered a header (<th scope="row">) and the
                input field the corresponding data.

                WFM, YMMV

                --
                Reply email address is a bottomless spam bucket.
                Please reply to the group so everyone can share.

                Comment

                • Els

                  #9
                  Re: how to layout forms with css

                  Neal wrote:
                  [color=blue]
                  > On Wed, 25 Aug 2004 17:44:13 -0400, Neal
                  > <neal413@yahoo. com> wrote:
                  >[color=green]
                  >> On 25 Aug 2004 21:38:47 GMT, Els <els.aNOSPAM@ti scali.nl>
                  >> wrote:[color=darkred]
                  >>> Here's me thinking: "this sounds so easy, but I'm sure it
                  >>> was a heck of a lot more complicated when I tried it
                  >>> once" ... Then I realised that was cause I wanted the
                  >>> labels right aligned... :-)[/color]
                  >>
                  >> form div {position: relative;}
                  >> form div label {display: block; width: 10em; text-align:
                  >> right;} form div input {position: absolute; top: 0; left:
                  >> 13em;}
                  >>
                  >> Works in Opera and IE.[/color][/color]

                  What does it do in other browsers?
                  (too lazy to try - I'm happy with my little tabled form)
                  [color=blue]
                  > Until you change text size in IE, dammit.[/color]

                  <g>
                  [color=blue]
                  > This fixes that.
                  >
                  > form div {position: relative; font-size: 100%;}
                  > form div label {display: block; width: 10em; text-align:
                  > right;} form div input {font-size: 100%; position:
                  > absolute; top: 0; left: 13em;}[/color]

                  Looks easy, and looks like it could work, but I'm sure I've
                  seen a far more complicated version, not sure if that had a
                  good reason or was just plain over the top. I think every row
                  had a div around it, then both the label and the input had a
                  div each, and there was floating somewhere too.

                  --
                  Els
                  Blog and other pages, mostly outdated.

                  Sonhos vem. Sonhos vão. O resto é imperfeito.
                  - Renato Russo -

                  Comment

                  • Brian

                    #10
                    Re: how to layout forms with css

                    Neal wrote:[color=blue]
                    > Harlan Messinger wrote:
                    >[color=green]
                    >> I'm of the camp that says that this is a tabular arrangement:
                    >> labels in one column, user input in another.[/color]
                    >
                    >
                    > But isn't the purpose of a table to offer a comparison amongst the
                    > data?[/color]

                    It can be. But I think your definition is a tad too narrow.
                    [color=blue]
                    > I think a table needs columns and rows which compare similar data,[/color]

                    A table should present information that can be related. My test: if the
                    data is rearranged, can the user still make sense of the data? With
                    layout tables, yes. With form data, the answer is no. To me, that says a
                    table is appropriate for a form.
                    [color=blue]
                    > Of course, I won't shoot you.[/color]

                    Well, that's good! :-)

                    --
                    Brian (remove ".invalid" to email me)

                    Comment

                    • Brian

                      #11
                      Re: how to layout forms with css

                      Neal wrote:
                      [color=blue]
                      > Roderik wrote:
                      >[color=green]
                      >> I was wondering how we could layout forms without tables so we
                      >> would have each input text field below each other.
                      >>
                      >> for example:
                      >> NAME: INPUT FIELD
                      >> PASSWORD: INPUT FIELD[/color]
                      >
                      > form div {position: relative;} form div label {width: 12em;} form div
                      > input {position: absolute; left: 13em;}[/color]

                      What a simple idea. I've always floated the label, but given all the css
                      float bugs, I wonder if this isn't a better solution.

                      --
                      Brian (remove ".invalid" to email me)

                      Comment

                      • Brian

                        #12
                        Re: how to layout forms with css

                        Neal wrote:
                        [color=blue]
                        > On Wed, 25 Aug 2004 17:44:13, Neal wrote:[color=green]
                        >>
                        >> form div {position: relative;}
                        >> form div label {display: block; width: 10em; text-align: right;}
                        >> form div input {position: absolute; top: 0; left: 13em;}
                        >>
                        >> Works in Opera and IE.[/color]
                        >
                        >
                        > Until you change text size in IE, dammit.[/color]

                        Second time this has come up tonight.
                        [color=blue]
                        > This fixes that.
                        >
                        > form div {position: relative; font-size: 100%;}[/color]

                        Yep. If you're going to do anything fancy layout-wise, you're best
                        off setting font-size: 100% in body.

                        --
                        Brian (remove ".invalid" to email me)

                        Comment

                        • Harlan Messinger

                          #13
                          Re: how to layout forms with css

                          Neal <neal413@yahoo. com> wrote:
                          [color=blue]
                          >On Wed, 25 Aug 2004 17:17:27 -0400, Harlan Messinger
                          ><h.messinger@c omcast.net> wrote:
                          >
                          >[color=green][color=darkred]
                          >>> NAME: INPUT FIELD
                          >>> PASSWORD: INPUT FIELD[/color]
                          >>
                          >> I'm of the camp that says that this is a tabular arrangement: labels in
                          >> one
                          >> column, user input in another.[/color]
                          >
                          >But isn't the purpose of a table to offer a comparison amongst the data? I
                          >think a table needs columns and rows which compare similar data, but this
                          >isn't for that purpose really.[/color]

                          The purpose of a TABLE is to present tabular data. "Data" can be
                          anything, including user-entered data or places for them to enter it.
                          The first paragraph of the Tables section of the spec:

                          "The HTML table model allows authors to arrange data -- text,
                          preformatted text, images, links, forms, form fields, other tables,
                          etc. -- into rows and columns of cells."


                          --
                          Harlan Messinger
                          Remove the first dot from my e-mail address.
                          Veuillez ôter le premier point de mon adresse de courriel.

                          Comment

                          • Neal

                            #14
                            Re: how to layout forms with css

                            On Thu, 26 Aug 2004 01:20:53 -0400, Harlan Messinger
                            <hmessinger.rem ovethis@comcast .net> wrote:
                            [color=blue]
                            > Neal <neal413@yahoo. com> wrote:
                            >[color=green]
                            >> But isn't the purpose of a table to offer a comparison amongst the
                            >> data? I
                            >> think a table needs columns and rows which compare similar data, but
                            >> this
                            >> isn't for that purpose really.[/color]
                            >
                            > The purpose of a TABLE is to present tabular data. "Data" can be
                            > anything, including user-entered data or places for them to enter it.
                            > The first paragraph of the Tables section of the spec:
                            >
                            > "The HTML table model allows authors to arrange data -- text,
                            > preformatted text, images, links, forms, form fields, other tables,
                            > etc. -- into rows and columns of cells."[/color]

                            I was just thinking about Barry Pearson too. ;) In his honor, I'll start
                            from the start. :D

                            The definition describes damn near anything. Even tabular layout. The
                            definition isn't that good. The only way to make sense of it is to look at
                            the element's name, table.

                            Clearly, img is meant to deliver an image, not some other object. And form
                            is obviously for a form. Their descriptions in the W3C documentation
                            reflect these roles.

                            Therefore, it's sensible to deduce that it "allows authors to arrange data
                            .... into rows and columns of cells" only if it's a table. And so we must
                            look at what tables are in real life.

                            Most definitions I see describe a table as a "relational database system"
                            - which is to say, all the row items have something unique in common, and
                            all the columns have something - the same thing - in common with each row.
                            And, it implies that it's meant for providing a relationship to the viewer.

                            Now, is the form we've been discussing a table? Some have argued basically
                            that it's a chart of rows relating to specific input content, comparing
                            the author's queries and the user's responses. I guess I am seeing tables
                            as being meant to communicate this relationship to the user, not as merely
                            a relationship that develops through the user's interaction. An HTML
                            table's purpose is to deliver information based in relations of data to a
                            curious user, not to simply act as an egg carton, holding whatever data
                            relationships we or a random user chooses to plug in. The table element no
                            longer seems to have a semantic approach, but becomes simply a rendering
                            device to align stuff we have a hard time with otherwise - which is
                            exactly the slippery slope we all want to avoid!

                            Maybe my view is in error, I'll have to ponder it. Never really gave it
                            much thought before now. But then again, maybe it's not...

                            Comment

                            • Harlan Messinger

                              #15
                              Re: how to layout forms with css

                              Neal <neal413@yahoo. com> wrote:
                              [color=blue]
                              >On Thu, 26 Aug 2004 01:20:53 -0400, Harlan Messinger
                              ><hmessinger.re movethis@comcas t.net> wrote:
                              >[color=green]
                              >> Neal <neal413@yahoo. com> wrote:
                              >>[color=darkred]
                              >>> But isn't the purpose of a table to offer a comparison amongst the
                              >>> data? I
                              >>> think a table needs columns and rows which compare similar data, but
                              >>> this
                              >>> isn't for that purpose really.[/color]
                              >>
                              >> The purpose of a TABLE is to present tabular data. "Data" can be
                              >> anything, including user-entered data or places for them to enter it.
                              >> The first paragraph of the Tables section of the spec:
                              >>
                              >> "The HTML table model allows authors to arrange data -- text,
                              >> preformatted text, images, links, forms, form fields, other tables,
                              >> etc. -- into rows and columns of cells."[/color]
                              >
                              >I was just thinking about Barry Pearson too. ;) In his honor, I'll start
                              > from the start. :D
                              >
                              >The definition describes damn near anything. Even tabular layout. The
                              >definition isn't that good. The only way to make sense of it is to look at
                              >the element's name, table.
                              >
                              >Clearly, img is meant to deliver an image, not some other object. And form
                              >is obviously for a form. Their descriptions in the W3C documentation
                              >reflect these roles.
                              >
                              >Therefore, it's sensible to deduce that it "allows authors to arrange data
                              >... into rows and columns of cells" only if it's a table. And so we must
                              >look at what tables are in real life.
                              >
                              >Most definitions I see describe a table as a "relational database system"
                              >- which is to say, all the row items have something unique in common, and
                              >all the columns have something - the same thing - in common with each row.
                              >And, it implies that it's meant for providing a relationship to the viewer.[/color]

                              I agree with all of that, and it's fully applicable to the arrangement
                              of data labels and entry fields.
                              [color=blue]
                              >
                              >Now, is the form we've been discussing a table? Some have argued basically
                              >that it's a chart of rows relating to specific input content, comparing
                              >the author's queries and the user's responses. I guess I am seeing tables
                              >as being meant to communicate this relationship to the user, not as merely
                              >a relationship that develops through the user's interaction.[/color]

                              I see no need to add that requirement to the definition of a table.
                              We're talking about a set of ordered pairs, (label, entry field), and
                              if you don't want to think of the fields as data, then the information
                              that the user will enter into them *is* data. Why would table-ness
                              depend on *who* enters the data into each cell?
                              [color=blue]
                              > An HTML
                              >table's purpose is to deliver information based in relations of data to a
                              >curious user, not to simply act as an egg carton, holding whatever data
                              >relationship s we or a random user chooses to plug in.[/color]

                              Data is data, no matter who plugs it in.
                              [color=blue]
                              >The table element no
                              >longer seems to have a semantic approach, but becomes simply a rendering
                              >device to align stuff we have a hard time with otherwise - which is
                              >exactly the slippery slope we all want to avoid![/color]

                              I don't see this as a consequence of using tables to arrange a form as
                              we have been discussing..
                              [color=blue]
                              >
                              >Maybe my view is in error, I'll have to ponder it. Never really gave it
                              >much thought before now. But then again, maybe it's not...[/color]


                              --
                              Harlan Messinger
                              Remove the first dot from my e-mail address.
                              Veuillez ôter le premier point de mon adresse de courriel.

                              Comment

                              Working...