Olivia Olivia - 14 days ago 5
HTML Question

HTML table with a percentage width, and a pixel limit

I've created a table with a width of 90% of the page, which is fine, unless the monitor is a widescreen - in which case, the items in the table are too spaced out. Is it possible to set a width of a table as the percentage of the page, but with a pixel width limit?
For example, a table that was 90% of the page, but had a limit of 1000px so it couldn't exceed that size.

<table align="center" style="width:90%;">
<tbody>
<tr>
<td>a</td>
<td>b</td>
</tr>
<tr>
<td>c</td>
<td>d</td>
</tr>
</tbody>



Answer

For your example code:

<table align="center" style="width:90%; max-width:1000px;">
<tbody>
    <tr>
        <td>a</td>
        <td>b</td>
    </tr>
    <tr>
        <td>c</td>
        <td>d</td>
    </tr>
</tbody>