Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "word-wrap: break-word" within a table [duplicate]

Possible Duplicate:
Word-wrap in a html table

This text behaves exactly the way I want on Google Chrome (and other modern browsers):

<div style="border: 1px solid black; width:100%; word-wrap: break-word;">   <p>     aaaaaaaaaaaaaaaa     bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb   </p> </div> 
  1. When the browser is wide enough, a+ and b+ are on the same line.

    aaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 
  2. As you narrow the browser, a+ and b+ are put on separate lines.

    aaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 
  3. When b+ can no longer fit, it is broken and put on two lines (for a total of three lines).

    aaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbb 

That's all great.

In my situation, however, this is not a div but a table, like so:

<table style="border:1px solid black; width:100%; word-wrap:break-word;">   <tr>     <td>       <p>         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb       </p>     </td>   </tr> </table> 

In this case, #1 and #2 happen, but not #3. That is, the table stops narrowing after step 2 and step 3 doesn't ever happen. The break-word doesn't seem to be filtering down.

Does anyone know how make #3 happen? The solution only need work in Chrome, but it it also worked in other browsers that would be even better.

P.S. "Don't use tables" is not helpful.

like image 791
Matthew Simoneau Avatar asked May 04 '11 20:05

Matthew Simoneau


People also ask

Does word-wrap work in a table?

Wrap Text Around a Table in Word. Right-click on the table and select “Table Properties.” In the Table tab, select the “Around” option. Adjust the wrapping by dragging and dropping the table, or by clicking “Positioning” in Table Properties.

How do you wrap text in a table cell in word?

Click on the "Properties" button. In the pop-up window that appears, click on the "Around" button underneath the bolded header, "Text Wrapping." This ensures that text will wrap around your table. Depending on your version of Word, you may have to click on the "Table" tab at the top left of the pop-up window.


1 Answers

table-layout: fixed will get force the cells to fit the table (and not the other way around), e.g.:

<table style="border: 1px solid black; width: 100%; word-wrap:break-word;               table-layout: fixed;">   <tr>     <td>         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb     </td>   </tr> </table> 
like image 148
Matthew Simoneau Avatar answered Sep 28 '22 15:09

Matthew Simoneau