Link to home
Start Free TrialLog in
Avatar of dbrunton
dbruntonFlag for New Zealand

asked on

Getting only one column in a table to word wrap.

I'm playing with HTML and have tables with a number of columns.  If the div they are in isn't wide enough then the contents in the columns will break and wrap.  However I'd like only one column to break and wrap with all of the others staying fixed no matter what is in them.

Is there an easy way to accomplish this?  I could specify the column widths (as a percentage or specify a fixed width) for those I don't want to break but that seems like work.  Is there an easier method?
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Can you post as a JSFiddle?
https://jsfiddle.net
You mean something like this?

http://jsfiddle.net/7usnjq5x/2/

I've configured the outer container so that you can use your mouse to adjust the size and see what happens. This is an example originally from https://stackoverflow.com/questions/3568262/css-columns-fixed-width-and-remainder that I've modified to better demonstrate the principle.
You can use the css white-space rule to prevent text from wrapping. The following will prevent wrapping on all but the first column:

td { white-space: nowrap; }
td:nth-child(1) { white-space: normal; }

Open in new window

Avatar of dbrunton

ASKER

Give us about six hours to work out if I can use JSFiddle.  Looks semi-interesting.

At present a code sample is here  http://jsfiddle.net/10kqxtfj/5/

The Spare Part column is the one I want to wrap.  All others I want to stay still.  The width here is 300 px for showing the wrapping.  It is normally about 700 px.
Hmm.

@Chris Stanyon - that looks interesting ...
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks everyone.

Chris's code did it.  I've got a little bit more experimenting to do as there are some <th> which might need to be smacked as well.

JSFiddle is interesting.  Thanks Shaun.

And Terry that code is scaring me.  I'm not that advanced in HTML and CSS but thanks for the time in putting it up.