Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fixed width for table cells

Status
Not open for further replies.

peterswan

Programmer
Sep 25, 2002
263
US
Hello,

I'm trying to set a fixed width for my table cells, but if I specify the width, and the person shrinks the browser width, the cell shrinks down to lower than the specified width, and the contents of the cell wraps.

However, what I'd like the cell to do in this case is remain at this width so the data doesn't wrap. I also do not want the cell to increase in size if the user widens the browser. If the data is too wide for the fixed width, I want the data to wrap in this case.

Is there a way to do this? I'm basically trying to set the width of the cell in the TD tag to remain at a certain width no matter what.

Thanks,

Peter [smile]
 
In your CSS, just define each TD.

Code:
td {
   width:40px;
}

if each TD has to be a different size, assign each td a class and set the width specifically in each class.


Code:
<td class="nameTD">

CSS:

td.nameTD {
   width:20000000px;
}


[monkey][snake] <.
 
simple way I would do it is...

style="width: Xpx"

X being the size you want, and px stands for pixels

of course there's always max-height,max-width,min-height, and min-width. Never used those, but I doubt you'll need to either.

----------------------------------------
Exactly where is the point that you are assassinated rather than murdered?
 
If you want your table layout to be completely fixed, I suggest you add that to your table declaration:
Code:
table {
  table-layout: fixed;
}
 
no, didn't work.

I forgot to mention that my table width is set to 100%. When the user shrinks the browser, the Name column (set with style sheets to 175 pixels) still shrinks down to well below 175. Is this supposed to happen?

I tried
{table-layout: fixed;}
but now it forces me to set a fixed width for all of the columns, or else the column data becomes "hidden" underneath the column borders.

What I really want is a way to keep table width=100% and somehow ensure that the column width of a certain column will stay at a specified width regardless of user interaction.

Am I forced to use a specific table width?

Thanks,

Peter [smile]
 
Try adding
Code:
white-space:nowrap;
to your css td definition

I haven't tested on a resize, but it should be fine.

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top