Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a scrollable matrix in html with tables
    text
    copied!<p>I want to have something like a matrix in a html page. The content of the table/matrix should be scrollable but the row and column titles should be fixed so they are always visible. </p> <p>I tried to do that with having 3 tables: one for the column-titles, one for the row-titles and one for the content itself. It looks fine when all the content fits on the page. However, as soon as there is not enough space to fit all the content, the whole thing gets messed up. How can I prevent this from happening and make the tables always appear on one line and add a scrollbar if necessary instead of moving the content table to the next line?</p> <p><img src="https://i.stack.imgur.com/FmCVv.png" alt="messed up matrix"> <img src="https://i.stack.imgur.com/2AioW.png" alt="matrix"></p> <p>This is my html:</p> <pre><code>&lt;div class="container"&gt; &lt;div class="tableparent"&gt; &lt;table class = "table rowtitle table-striped"&gt; &lt;tr&gt;&lt;td&gt;Logo&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;4&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;5&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;6&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;table class="table columntitle table-striped"&gt; &lt;tr&gt; &lt;th&gt;1&lt;/th&gt; &lt;th&gt;2&lt;/th&gt; &lt;th&gt;3&lt;/th&gt; &lt;th&gt;4&lt;/th&gt; &lt;th&gt;5&lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table class="table table-striped"&gt; &lt;tr&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;X&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;X&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>And this is the relevant part of the CSS:</p> <pre><code> table { max-width: 100%; background-color: transparent; border-collapse: collapse; border-spacing: 0; } .table { white-space: nowrap; } .table th, .table td { padding: 8px; line-height: 20px; text-align: center; vertical-align: top; border: 1px solid #dddddd; } .table th { font-weight: bold; } .table-striped tbody &gt; tr:nth-child(odd) &gt; td, .table-striped tbody &gt; tr:nth-child(odd) &gt; th { background-color: #f9f9f9; } .rowtitle { float: left; padding: 8px; border-right: 0px; height: 200px; } .rowtitle th, .rowtitle td { border-right: 0px; } .columntitle { padding: 8px; border-bottom: 0px; } .columntitle th, .columntitle td { border-bottom: 0px; } .tableparent { width: 100%; } </code></pre> <p>Any help appreciated!</p>
 

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