Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html table with width 100% does not work with long text

I have the following structure

<table cellspacing="0" cellpadding="0" width="100%">
<tr>
    <td style="width:60px;">
        ...
    </td>
    <td>
        <div style="width:100%;overflow-x:hidden;">
            PROBLEMS ARE HERE
        </div>
    </td>
</tr>
...
</table>

The first td takes 60px, the second one takes the rest of the 100%, but when I have some long text with no spaces and no dashes the table becomes larger then the 100%. How to display the non-breakable text in one line or on multiple lines (both ways are acceptable) and keep the table on 100% of the screen? I've tried to fix this with overflow-hidden but it has no effect.

Here's a screenshot of the problem:link

like image 278
Дамян Станчев Avatar asked Nov 18 '11 11:11

Дамян Станчев


People also ask

What does width 100% do in HTML?

If you set the width to 100% on the body element you will have a full page width. This is essentially equivalent to not setting a width value and allowing the default. If you want to use the body element as a smaller container and let the HTML element fill the page, you could set a max-width value on the body.

How do I fix the width of a table in HTML?

To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width.

How do you make a full width occupy table?

You need to set the margin of the body to 0 for the table to stretch the full width. Alternatively, you can set the margin of the table to a negative number as well.

How do you change the width of the table to 100 percent of the page width?

Click inside the table. On the menu, select Table > AutoFit > AutoFit to Window.


1 Answers

Set table-layout : fixed in your css or <table style='table-layout : fixed'> that oughta fix it.

Here is the code sample. Check it out.

like image 133
Ashwin Krishnamurthy Avatar answered Sep 24 '22 13:09

Ashwin Krishnamurthy