Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Making a <td> as small a width as possible

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nathan Sokalski - 06 Oct 2007 01:37 GMT
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.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

Mark Rae [MVP] - 06 Oct 2007 02:16 GMT
[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...

Signature

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

Nathan Sokalski - 06 Oct 2007 03:20 GMT
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).
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

> [cross-posting removed]
>
[quoted text clipped - 12 lines]
> Check in View Source for what markup is actually being included in the
> cell in question...
Alexey Smirnov - 06 Oct 2007 13:36 GMT
> Here is an example of a <td> using more space than necessary:
>
[quoted text clipped - 8 lines]
>    </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;background-
color:Orange;">

Hope it helps
Singapore Web Design - 06 Oct 2007 12:04 GMT
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

Signature

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

>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
[quoted text clipped - 3 lines]
>prevent a <td> from being stretched to a larger width than necessary?
>Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.