I want to wrap some text that is added to a <td>
element.
I have tried with style="word-wrap: break-word;" width="15%"
.
But it is not wrapping the text. Is it mandatory to give it 100% width?
I have other controls to display so only 15% width is available.
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
- Adding a timeout to a render function in ReactJS
This worked for me with some css frameworks (material design lite [MDL]).
Apply classes to your TDs, apply the appropriate widths (remember to leave one of them without a width so it assumes the remainder of the width), then apply the appropriate styles. Copy and paste the code below into an editor and view in a browser to see it function.
Actually wrapping of text happens automatically in tables. The blunder people commit while testing is to hypothetically assume a long string like "ggggggggggggggggggggggggggggggggggggggggggggggg" and complain that it doesn't wrap. Practically there is no word in English that is this long and even if there is, there is a faint chance that it will be used within that
<td>
.Try testing with sentences like "Counterposition is superstitious in predetermining circumstances".
use
word-break
it can be used without stylingtable
totable-layout: fixed
table-layout:fixed
will resolve the expanding cell problem, but will create a new one. IE by default will hide the overflow but Mozilla will render it outside the box.Another solution would be to use:
overflow:hidden;width:?px
I believe you've encountered the catch 22 of tables. Tables are great for wrapping up content in a tabular structure and they do a wonderful job of "stretching" to meet the needs of the content they contain.
By default the table cells will stretch to fit content... thus your text just makes it wider.
There's a few solutions.
1.) You can try setting a max-width on the TD.
2.) You can try putting your text in a wrapping element (e.g. a span) and set constraints on it.
Be aware though that older versions of IE don't support min/max-width.
Since IE doesn't support max-width natively you'll need to add a hack if you want to force it to. There's several ways to add a hack, this is just one.
On page load, for IE6 only, get the rendered width of the table (in pixels) then get 15% of that and apply that as the width to the first TD in that column (or TH if you have headers) again, in pixels.