Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Making a <td> as small a width as possible

Reply
Thread Tools

Making a <td> as small a width as possible

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-06-2007
I have a <td> that contains several elements, some of which are
left-aligned, right-aligned, or centered. I do not know the widths of these
elements beforehand, so I cannot give my <td> a fixed width. I want the <td>
to have as small a width as possible without causing anything to wrap, but
IE seems to want to make it bigger. Does anybody know of a good way to
prevent a <td> from being stretched to a larger width than necessary?
Thanks.
--
Nathan Sokalski

http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      10-06-2007
"Nathan Sokalski" <> wrote in message
news:...

[cross-posting removed]

>I have a <td> that contains several elements, some of which are
>left-aligned, right-aligned, or centered. I do not know the widths of these
>elements beforehand, so I cannot give my <td> a fixed width. I want the
><td> to have as small a width as possible without causing anything to wrap,
>but IE seems to want to make it bigger. Does anybody know of a good way to
>prevent a <td> from being stretched to a larger width than necessary?


A <td> will expand to fit its contents. However, if other rows have more
data in the corresponding cell, then obviously the entire column will expand
to fit the contents of the largest cell.

Check in View Source for what markup is actually being included in the cell
in question...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-06-2007
Here is an example of a <td> using more space than necessary:

<table>
<tr>
<td>
<span style="float:left;">Float Left</span>
<span style="float:right;">Float Right</span><br/>
<div
style="width:500px;height:500px;background-color:Orange;">&nbsp;</div>
</td>
</tr>
</table>

You will notice that neither the table or td has a set width, but the float
right hangs over the edge of the div. The table could easily be no more than
the width of the div (in this case 500px) and still fit both span tags in.
Do the floats have anything to do with the problem? I use floats because I
want the spans on the left and right of the same line, and in my code the
width of the div is dynamic (my code also involves more cells than this).
--
Nathan Sokalski

http://www.nathansokalski.com/

"Mark Rae [MVP]" <> wrote in message
news:...
> "Nathan Sokalski" <> wrote in message
> news:...
>
> [cross-posting removed]
>
>>I have a <td> that contains several elements, some of which are
>>left-aligned, right-aligned, or centered. I do not know the widths of
>>these elements beforehand, so I cannot give my <td> a fixed width. I want
>>the <td> to have as small a width as possible without causing anything to
>>wrap, but IE seems to want to make it bigger. Does anybody know of a good
>>way to prevent a <td> from being stretched to a larger width than
>>necessary?

>
> A <td> will expand to fit its contents. However, if other rows have more
> data in the corresponding cell, then obviously the entire column will
> expand to fit the contents of the largest cell.
>
> Check in View Source for what markup is actually being included in the
> cell in question...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Singapore Web Design
Guest
Posts: n/a
 
      10-06-2007
Hello,

If the containing table and td have no width set, the td width will be the
size of the column.

To prevent the wrapping, use the nowrap attribute. See
http://www.htmlcodetutorial.com/tables/_TD_NOWRAP.html

--
Singapore Web Design
http://www.bootstrike.com/Webdesign/
Singapore Web Hosting
http://www.bootstrike.com/WinXP/faq.html
Windows XP FAQ

"Nathan Sokalski" <> wrote in message
news:...
>I have a <td> that contains several elements, some of which are
>left-aligned, right-aligned, or centered. I do not know the widths of these
>elements beforehand, so I cannot give my <td> a fixed width. I want the
><td> to have as small a width as possible without causing anything to wrap,
>but IE seems to want to make it bigger. Does anybody know of a good way to
>prevent a <td> from being stretched to a larger width than necessary?
>Thanks.
> --
> Nathan Sokalski
>
> http://www.nathansokalski.com/
>



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-06-2007
On Oct 6, 4:20 am, "Nathan Sokalski" <njsokal...@hotmail.com> wrote:
> Here is an example of a <td> using more space than necessary:
>
> <table>
> <tr>
> <td>
> <span style="float:left;">Float Left</span>
> <span style="float:right;">Float Right</span><br/>
> <div
> style="width:500px;height:500px;background-color:Orange;"> </div>
> </td>
> </tr>
> </table>
>


Hi Nathan

you have to set clear:both to make the div element go below

<div style="CLEAR:BOTH;width:500px;height:500px;backgro und-
color:Orange;">

Hope it helps

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using % on a table width, is it possible to get the width in pixel size? RMZ Javascript 2 08-01-2007 11:01 PM
Textbox width scaling to width of data not width of page? AndrewF ASP .Net 1 10-10-2005 04:38 PM
JComboBox width, dropdown list width Xu Java 11 07-15-2005 11:54 PM
Table width and columns width kris HTML 11 11-18-2003 06:49 AM
Re: resized image in table extends table width to original image width Sean Jorden HTML 1 08-19-2003 08:59 AM



Advertisments