column width won't behave

Discussion in 'HTML' started by Ben, Oct 13, 2005.

  1. Ben

    Ben Guest

    Hi
    I have a report that I need to display in a table format, and the field
    lengths vary for all of the columns. For the majority, I am happy for
    the width to just adjust according to the width of the text, but I
    don't want the text to go onto the next line where there is a space
    (unless it's a really long field). here is my table header

    <table border="1" cellspacing="0" cellpadding="5" width="100%">
    <thead>
    <tr>
    <td>Contract#</td>
    <td>Order#</td>
    <td width='200'>Description</td>
    <td>Style</td>
    <td>Colour</td>
    <td>Units</td>
    <td>Price (R)</td>
    <td width="30">Value (R)</td>
    </tr>
    </thead>

    no matter what I set the width to for the description field, it comes
    out looking exacly the same.

    can anybody tell me what I'm doing wrong?
    thanks!
     
    Ben, Oct 13, 2005
    #1
    1. Advertising

  2. "Ben" <> wrote:

    > I have a report that I need to display in a table format, and the field
    > lengths vary for all of the columns. For the majority, I am happy for
    > the width to just adjust according to the width of the text, but I
    > don't want the text to go onto the next line where there is a space
    > (unless it's a really long field).


    There are several ways to prevent that. The choice between depends on the
    content and context, especially on the nature of the long text inside the
    cell.

    > <table border="1" cellspacing="0" cellpadding="5" width="100%">


    Hints: Don't set width to 100%, because it will unnecessarily stretch the
    table when not needed. Consider using CSS instead of cellpadding, since
    with CSS, you can set vertical padding (which is often not needed or needed
    just a little) smaller than horizontal padding.

    > <td width='200'>Description</td>


    Don't set widths, especially not in pixels, since you cannot know the font
    size variation.

    > no matter what I set the width to for the description field, it comes
    > out looking exacly the same.


    I don't think so. But depending on the content as a whole and the canvas
    width, much of the variation in the width setting might indeed have no
    effect.

    If you wish to prevent all line breaks inside a cell, you can use of the
    following:

    <td nowrap>Description</td>

    <td><nobr>Description</nobr></td> (nonstandard)

    <td style="white-space:nowrap">Description</td>

    Note: These ways often fail if you set a width for the cell!

    Hint: It is sufficient to prevent breaks inside the cell of a column that
    has the largest width requirement.

    If you wish to prevent just some line breaks, it is often best to use
    no-break spaces instead of normal spaces in the cell content.

    > can anybody tell me what I'm doing wrong?


    Well, you didn't post a URL that would illustrate the problem in its real
    context. But there was perhaps enough information for a partly useful
    analysis.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
     
    Jukka K. Korpela, Oct 13, 2005
    #2
    1. Advertising

  3. Ben

    Ben Guest

    thank you that is very useful, I unfortunately can't post the url
    because it is for an intranet site. The problem that I have is that the
    data I am putting into the table is out of a database - so I have no
    control over the format of the contents of each cell (i.e. I can't put
    &nbsp; inside, unless I replace all the spaces with &nbsp, which won't
    be much good either). The <td nowrap> tag will be VERY useful (didn't
    know about that) for some of the formatting, but the description field
    needs to go onto two or three lines (otherwise it will be far too
    wide). Once again I apologise for not being able to post my code, it is
    sort of a confidential site (nothing too exciting though). I don't
    understand why me setting the width of the column has no effect? that
    would definitely be the most obvious solution.
     
    Ben, Oct 14, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AndrewF
    Replies:
    1
    Views:
    811
    Bruce Barker
    Oct 10, 2005
  2. ssk
    Replies:
    5
    Views:
    5,595
    Jukka K. Korpela
    Oct 30, 2006
  3. David Basford
    Replies:
    3
    Views:
    2,471
    BootNic
    Sep 30, 2007
  4. Replies:
    0
    Views:
    945
  5. Carl Howarth

    DG Column Width vs Table Column Width

    Carl Howarth, Oct 22, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    277
    Eliyahu Goldin
    Oct 24, 2004
Loading...

Share This Page