468,277 Members | 1,522 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,277 developers. It's quick & easy.

Making a <td> as small a width as possible

I have a <tdthat 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 <tda 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 <tdfrom being stretched to a larger width than necessary?
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Oct 6 '07 #1
4 3905
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:uR**************@TK2MSFTNGP03.phx.gbl...

[cross-posting removed]
>I have a <tdthat 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 <tda fixed width. I want the
<tdto 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 <tdfrom being stretched to a larger width than necessary?
A <tdwill 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

Oct 6 '07 #2
Here is an example of a <tdusing 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
nj********@hotmail.com
http://www.nathansokalski.com/

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:u3**************@TK2MSFTNGP06.phx.gbl...
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:uR**************@TK2MSFTNGP03.phx.gbl...

[cross-posting removed]
>>I have a <tdthat 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 <tda fixed width. I want
the <tdto 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 <tdfrom being stretched to a larger width than
necessary?

A <tdwill 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

Oct 6 '07 #3
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" <nj********@hotmail.comwrote in message
news:uR**************@TK2MSFTNGP03.phx.gbl...
>I have a <tdthat 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 <tda fixed width. I want the
<tdto 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 <tdfrom being stretched to a larger width than necessary?
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Oct 6 '07 #4
On Oct 6, 4:20 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
Here is an example of a <tdusing 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

Oct 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by bissatch | last post: by
8 posts views Thread by effendi | last post: by
1 post views Thread by neverstill | last post: by
5 posts views Thread by Magnus Blomberg | last post: by
3 posts views Thread by waqasahmed996 | last post: by
3 posts views Thread by yawnmoth | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.