Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I’m afraid there’s no direct solution. You could play with JavaScript, creating copy of the table containing only the first row, get its width, discard the copy, and use the width to set the width of your real table. Combined with the setting <code>table-layout: fixed</code>, this should handle the situation. You can simplify the approach so that you do not create a copy of the table but instead remove the second row, later add it back. It gets rather ugly:</p> <pre><code>&lt;!doctype html&gt; &lt;title&gt;Hack&lt;/title&gt; &lt;style&gt; table { table-layout: fixed } tr:first-child td { white-space: nowrap } &lt;/style&gt; &lt;table id=tbl&gt; &lt;tbody id=tbody&gt; &lt;tr&gt; &lt;td id=cell1&gt;Cell 1&lt;/td&gt; &lt;td id=cell2&gt;Cell 2&lt;/td&gt; &lt;/tr&gt; &lt;tr id=row2&gt;&lt;td colspan=2&gt; Very long cell that should just be as long as the first two cells and wrap, but not take all the screen width. &lt;/table&gt; &lt;script&gt; var tbl = document.getElementById('tbl'); var tbody = document.getElementById('tbody'); var row2 = document.getElementById('row2'); var cell1 = document.getElementById('cell1'); var cell2 = document.getElementById('cell2'); tbody.removeChild(row2); var width = tbl.clientWidth; var width1 = cell1.clientWidth; var width2 = cell2.clientWidth; tbody.appendChild(row2); cell1.style.width = width1 + 'px'; cell2.style.width = width2 + 'px'; tbl.style.width = width + 'px'; &lt;/script&gt; </code></pre> <p>A completely different idea is to use a workaround where the long text is not in a cell but in a <code>caption</code> element, placed at the bottom of the table:</p> <pre><code>&lt;table&gt; &lt;caption align=bottom style="text-align: left"&gt; Very long cell that should just be as long as the first two cells and wrap, but not take all the screen width. &lt;tr&gt; &lt;td&gt;Cell 1&lt;/td&gt; &lt;td&gt;Cell 2&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload