Reputation: 12487
This is my code: http://jsfiddle.net/spadez/mVX93/19/
#my-table{width:100%;border-collapse:collapse;} /*or whatever width you want*/
#my-table td{width:2000px;padding:4px;border:1px solid #000;vertical-align:top;} /*something big or 100%*/
I'm trying to make it so no matter how many columns there are, each one is an equal width. However, this approach should work but it doesn,t we can see one is clearly bigger because it has bigger content.
Can this be done, without having to specify specific CSS for the number of columns?
Upvotes: 0
Views: 77
Reputation: 71140
Simply use:
#my-table{
width:100%;
border-collapse:collapse;
table-layout:fixed
}
#my-table td{
padding:4px;
border:1px solid #000;
vertical-align:top;
word-break:break-word; /* <-- ensure the line of dots can be broken */
}
The word-break CSS property is used to specify how (or if) to break lines within words.
You may also want to add word-wrap:break-word;
The word-wrap CSS property is used to specify whether or not the browser may break lines within words in order to prevent overflow (in other words, force wrapping) when an otherwise unbreakable string is too long to fit in its containing box.
Upvotes: 2
Reputation: 125423
Set table-layout:fixed
on the table, and remove fixed width you have set on td
.
#my-table{
width:100%;
border-collapse:collapse;
table-layout:fixed
}
#my-table td{
padding:4px;
border:1px solid #000;
vertical-align:top;
}
Upvotes: 3