views:

48

answers:

3

In the following table, how do I align the data in td cells such that we do not get a horizontal scroll bar, using CSS?

Also the requirement is that the height of the table should be adjusted automatically..

<table> 
   <tr><th>name</th>
   <th>info</th></tr>
   <tr><td>Harry</td>
     <td>suminfosuminfosuminfosuminfosum infosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfos uminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfo<td></tr>
   <tr><td>test</td><td>test data</td></tr>
</table>
A: 

To support all browser go for this

.workbreak {
      word-wrap: break-word;      /* IE 5.5-7 */
      white-space: -moz-pre-wrap; /* Firefox 1.0-2.0 */
      white-space: pre-wrap;      /* current browsers */
}

<table> 
   <tr><th>name</th>
   <th>info</th></tr>
   <tr><td>Harry</td>
     <td class="workbreak">suminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfosuminfo<td></tr>
   <tr><td>test</td><td>test data</td></tr>
</table>

For more detail : https://developer.mozilla.org/en/CSS/white-space

Pranay Rana
Not work for me mozilla 3.0.4 on linux
Salil
yes it doesnt work on mozilla
Hulk
yes its not supported in Mozila to work with it try white-space: pre-wrap in FF
Pranay Rana
it should be word-wrap and this will only work with css3 capable browsers
corroded
@pranay:- nope that also not working for me.
Salil
check the answer now
Pranay Rana
Salil
see the link in answer according to it style sheet must work in mozila
Pranay Rana
@Salil try this http://www.css3.com/css-word-wrap/
corroded
A: 

The extra long cell needs word-wrap:break-word.

egrunin
A: 

Try:

table {
  table-layout: fixed; 
  word-wrap: break-word; 
  width: 600px; /* or whatever you like */
}
Ken Redler
Not work for me mozilla 3.0.4 on linux
Salil