Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap text using CSS? [duplicate]

Tags:

css

word-wrap

<td>gdfggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg</td> 

How do I get text like this to wrap in CSS?

like image 955
keruilin Avatar asked Oct 16 '10 16:10

keruilin


People also ask

How do you force text wrap in CSS?

You can force long (unbroken) text to wrap in a new line by specifying break-word with the word-wrap property. For example, you can use it to prevent text extending out the box and breaking the layout. This commonly happens when you have a long URL in the sidebar or comment list.

How do I wrap text around an image in CSS?

Enter . left { float: left; padding: 0 20px 20px 0;} to the stylesheet to use the CSS "float" property. (Use right to align the image to the right.) If you view your page in a browser, you'll see the image is aligned to the left side of the page and the text wraps around it.


2 Answers

If you type "AAAAAAAAAAAAAAAAAAAAAARRRRRRRRRRRRRRRRRRRRRRGGGGGGGGGGGGGGGGGGGGG" this will produce:

AARRRRRRRRRRRRRRRRRRRR RRGGGGGGGGGGGGGGGGGGGG G 

I have taken my example from a couple different websites on google. I have tested this on ff 5.0, IE 8.0, and Chrome 10. It works on all of them.

.wrapword {     white-space: -moz-pre-wrap !important;  /* Mozilla, since 1999 */     white-space: -pre-wrap;      /* Opera 4-6 */     white-space: -o-pre-wrap;    /* Opera 7 */     white-space: pre-wrap;       /* css-3 */     word-wrap: break-word;       /* Internet Explorer 5.5+ */     white-space: -webkit-pre-wrap; /* Newer versions of Chrome/Safari*/     word-break: break-all;     white-space: normal; }  <table style="table-layout:fixed; width:400px">     <tr>         <td class="wrapword"></td>     </tr> </table> 
like image 131
Stirling Avatar answered Oct 22 '22 13:10

Stirling


Try doing this. Works for IE8, FF3.6, Chrome

<body>   <table>     <tr>       <td>         <div style="word-wrap: break-word; width: 100px">gdfggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg</div>       </td>     </tr>   </table> </body> 
like image 21
Gaurav Saxena Avatar answered Oct 22 '22 12:10

Gaurav Saxena