1

My code is this :

<div style="width: 300px;">
    <table width="100%" border="2px solid blue">
        <tr>
            <td style="width:30%">Player</td>
            <td style="width:30%">Club</td>
            <td style="width:30%">Country</td>
        </tr>
        <tr>
            <td style="width:30%">HazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazard</td>
            <td style="width:30%">Chelsea</td>
            <td style="width:30%">Belgium</td>
        </tr>
        <tr>
            <td>Ronaldo</td>
            <td>Real Madrid</td>
            <td>Portugal</td>
        </tr>
        <tr>
            <td>Messi</td>
            <td>Barcelona</td>
            <td>Argentina</td>
        </tr>
    </table>
</div>

The result is this :

html table

I tried to add width=30% in the column player, but it's still not working.

2

3 Answers 3

7

it's beacause your text is too large use this may help you

<style>
table tr td
{
  word-break: break-all;
  }
</style>
0
5

Moob was before me, use word-wrap:break-word; but also use table-layout:fixed

css code

table{
    table-layout: fixed;
}
td {
    word-wrap:break-word;
}
0
1

That's because "HazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazardHazard" is stretching it.

Table cells will stretch to fit their content, and if they can't break, they will keep stretching.

If it was "Hazard hazard..." etc with spaces, it would break as expected. The same would happen if you put a large image in the table cell.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.