width in table

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

    width in table

    Hi,

    Maybe this is a simple question, but I can't seem to get it to work.
    Let's say I have this table:

    <table style="width: 300px">
    <tr>
    <th>Header</th>
    <td>1</td>
    <td>22</td>
    <td>333</td>
    </tr>
    </table>

    How can I use CSS 2 to make the th take minimal width and let the other
    columns divide the rest of width equally. Also I do not know how many
    data columns I have.
  • Spartanicus

    #2
    Re: width in table

    Robert <robert@noreply .x> wrote:
    [color=blue]
    >Maybe this is a simple question, but I can't seem to get it to work.
    >Let's say I have this table:
    >
    > <table style="width: 300px">
    > <tr>
    > <th>Header</th>
    > <td>1</td>
    > <td>22</td>
    > <td>333</td>
    > </tr>
    > </table>
    >
    >How can I use CSS 2 to make the th take minimal width and let the other
    >columns divide the rest of width equally. Also I do not know how many
    >data columns I have.[/color]



    Note that it's hard to imagine a valid reason to fix the width of a
    table, especially when using the px unit and when the content contains
    text. If the table is used for layout purposes then the correct answer
    is stop doing that.

    --
    Spartanicus

    Comment

    • Disco Octopus

      #3
      Re: width in table

      Robert wrote on 26/04/2005 :[color=blue]
      > Hi,
      >
      > Maybe this is a simple question, but I can't seem to get it to work.
      > Let's say I have this table:
      >
      > <table style="width: 300px">
      > <tr>
      > <th>Header</th>
      > <td>1</td>
      > <td>22</td>
      > <td>333</td>
      > </tr>
      > </table>
      >
      > How can I use CSS 2 to make the th take minimal width and let the other
      > columns divide the rest of width equally. Also I do not know how many data
      > columns I have.[/color]

      as you dont know the amount of columns you will have, I am guessing
      that these are built dynamically. is that correct? if so, then perhaps
      you could do a litle run-time width calculations... .
      <psuedo_sorta_c ode>
      var_width = 100 / (var_column_cou nt + 1) ; // add one for the <th>
      write the var_width to the width placeholder in the HTML template.
      (perhaps search_replace the var_width placeholder.
      </psuedo_sorta_co de>

      your HTML template may look like this.

      <table style="width: 300px">
      <tr>
      <th style="width:{v ar_width}%;">He ader</th>
      <td style="width:{v ar_width}%;">1</td>
      <td style="width:{v ar_width}%;">22 </td>
      <td style="width:{v ar_width}%;">33 3</td>
      </tr>
      </table>

      --
      a beef jerky site http://www.choicebeefjerky.com.au
      not a beef jerky site http://mycoolwheels.com/vote.cmks
      nobody ever dreams of working for the man

      Comment

      • Robert

        #4
        Re: width in table

        Spartanicus wrote:[color=blue]
        > Robert <robert@noreply .x> wrote:
        >
        >[color=green]
        >>Maybe this is a simple question, but I can't seem to get it to work.
        >>Let's say I have this table:
        >>
        >> <table style="width: 300px">
        >> <tr>
        >> <th>Header</th>
        >> <td>1</td>
        >> <td>22</td>
        >> <td>333</td>
        >> </tr>
        >> </table>
        >>
        >>How can I use CSS 2 to make the th take minimal width and let the other
        >>columns divide the rest of width equally. Also I do not know how many
        >>data columns I have.[/color]
        >
        >
        > http://homepage.ntlworld.com/spartanicus/robert.htm[/color]

        This only works if the number of TD columns are exactly 3.
        [color=blue]
        > Note that it's hard to imagine a valid reason to fix the width of a
        > table, especially when using the px unit and when the content contains
        > text.[/color]

        Because I like the other tables I generate to be of equal size.
        [color=blue]
        > If the table is used for layout purposes then the correct answer
        > is stop doing that.[/color]

        No, it's not for the layout of images or something like that.

        Comment

        • Robert

          #5
          Re: width in table

          Disco Octopus wrote:[color=blue]
          > as you dont know the amount of columns you will have, I am guessing that
          > these are built dynamically. is that correct? if so, then perhaps you
          > could do a litle run-time width calculations... .[/color]

          Yes I thought about this too. Just was hoping to let CSS work this out
          automatically. I guess my expectations for CSS were too high :)

          Comment

          • Rob_W

            #6
            Re: width in table

            Robert wrote:[color=blue]
            > Disco Octopus wrote:
            >[color=green]
            >> as you dont know the amount of columns you will have, I am guessing
            >> that these are built dynamically. is that correct? if so, then perhaps
            >> you could do a litle run-time width calculations... .[/color]
            >
            >
            > Yes I thought about this too. Just was hoping to let CSS work this out
            > automatically. I guess my expectations for CSS were too high :)[/color]

            Your expectations weren't too high, they were wrong.
            CSS is about style not about calculating.

            RW

            Comment

            • Robert

              #7
              Re: width in table

              Rob_W wrote:[color=blue]
              > Robert wrote:
              >[color=green]
              >> Disco Octopus wrote:
              >>[color=darkred]
              >>> as you dont know the amount of columns you will have, I am guessing
              >>> that these are built dynamically. is that correct? if so, then
              >>> perhaps you could do a litle run-time width calculations... .[/color]
              >>
              >>
              >>
              >> Yes I thought about this too. Just was hoping to let CSS work this out
              >> automatically. I guess my expectations for CSS were too high :)[/color]
              >
              >
              > Your expectations weren't too high, they were wrong.
              > CSS is about style not about calculating.[/color]

              Having to divide the width between columns is style.

              Comment

              • Jim Moe

                #8
                Re: width in table

                Robert wrote:[color=blue]
                >
                > How can I use CSS 2 to make the th take minimal width [...]
                >[/color]
                th {width: 0%;}


                --
                jmm dash list (at) sohnen-moe (dot) com
                (Remove .AXSPAMGN for email)

                Comment

                • Disco Octopus

                  #9
                  Re: width in table

                  Robert wrote :[color=blue]
                  > Rob_W wrote:[color=green]
                  >> Robert wrote:
                  >>[color=darkred]
                  >>> Disco Octopus wrote:
                  >>>
                  >>>> as you dont know the amount of columns you will have, I am guessing that
                  >>>> these are built dynamically. is that correct? if so, then perhaps you
                  >>>> could do a litle run-time width calculations... .
                  >>>
                  >>>
                  >>>
                  >>> Yes I thought about this too. Just was hoping to let CSS work this out
                  >>> automatically. I guess my expectations for CSS were too high :)[/color]
                  >>
                  >>
                  >> Your expectations weren't too high, they were wrong.
                  >> CSS is about style not about calculating.[/color]
                  >
                  > Having to divide the width between columns is style.[/color]

                  Indeed, but doing the actual dividing to work out what the width should
                  be, is not style.

                  --
                  a beef jerky web site : http://www.choicebeefjerky.com.au
                  not a beef jerky web site : http://mycoolfish.com/vote.cmks
                  dont pick your nose if it is sore

                  Comment

                  • Robert

                    #10
                    Re: width in table

                    Disco Octopus wrote:[color=blue][color=green]
                    >> Having to divide the width between columns is style.[/color]
                    >
                    >
                    > Indeed, but doing the actual dividing to work out what the width should
                    > be, is not style.[/color]

                    If I set the width to a certain percentage there needs to be some
                    dividing too. To have the ability to set a relative 'weight' does not
                    make those calculations much harder. Well... it sure would be very
                    useful I think.

                    Comment

                    Working...