title: Building a variable covariance-table
body: <p>I want to create a covariance-table that shows all possible combinations between 3-10 inputs.</p>
  <p>The image below shows a 11x11 table for 10 inputs, and a 4x4 table for 3 inputs. The user can choose anywhere between 3 and 10 inputs, and the table can therefore be in any size between those pictured.</p>
  <p><a href="https://i.stack.imgur.com/Bvokt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bvokt.png" alt="enter image description here" /></a>.</p>
  <p>Making this table using HTML-tables seem to be a poor strategy, which is why I decided to use DIVs and CSS Grid instead. As you can guess, it was a bothersome solution with a lot of repetitive code - and that was only for 10 inputs! I need to repeat the code 7 more times to make it possible for the user to combine less than 10 inputs, and then use PHP to calculate the number of inputs and exclude (with PHP) all the irrelevant tables and keep the one that matches the number of inputs. Which is a lot of work.</p>
  <p>What is the best strategy for carrying this out?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>div#covariance {
              display: grid;
              grid-template-columns: auto 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
              border: 1px solid black;
              width: fit-content;
              grid-gap: 0.1em;
              background-color: black;
  
              grid-template-rows: auto 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
              grid-template-areas:
                  ". title1h title2h title3h title4h title5h title6h title7h title8h title9h title10h"
                  "title1v v1h1 v1h2 v1h3 v1h4 v1h5 v1h6 v1h7 v1h8 v1h9 v1h10"
                  "title2v v2h1 v2h2 v2h3 v2h4 v2h5 v2h6 v2h7 v2h8 v2h9 v2h10"
                  "title3v v3h1 v3h2 v3h3 v3h4 v3h5 v3h6 v3h7 v3h8 v3h9 v3h10"
                  "title4v v4h1 v4h2 v4h3 v4h4 v4h5 v4h6 v4h7 v4h8 v4h9 v4h10"
                  "title5v v5h1 v5h2 v5h3 v5h4 v5h5 v5h6 v5h7 v5h8 v5h9 v5h10"
                  "title6v v6h1 v6h2 v6h3 v6h4 v6h5 v6h6 v6h7 v6h8 v6h9 v6h10"
                  "title7v v7h1 v7h2 v7h3 v7h4 v7h5 v7h6 v7h7 v7h8 v7h9 v7h10"
                  "title8v v8h1 v8h2 v8h3 v8h4 v8h5 v8h6 v8h7 v8h8 v8h9 v8h10"
                  "title9v v9h1 v9h2 v9h3 v9h4 v9h5 v9h6 v9h7 v9h8 v9h9 v9h10"
                  "title10v v10h1 v10h2 v10h3 v10h4 v10h5 v10h6 v10h7 v10h8 v10h9 v10h10"
              ;
          }
  
          div.title, div.entry {
              display: flex;
              align-items: center;
              justify-content: center;
              text-align: center;
              height: 3em;
              width: 3em;
              background-color: white;
          }
  
          div.title {
              background-color: lightgrey;
          }
          div.horizontal {
              text-align: center;
              //transform: rotate(-90deg);
          }
          div.entry {
              display: flex;
          }
  
          div#title1v {grid-area: title1v;}
          div#title2v {grid-area: title2v;}
          div#title3v {grid-area: title3v;}
          div#title4v {grid-area: title4v;}
          div#title5v {grid-area: title5v;}
          div#title6v {grid-area: title6v;}
          div#title7v {grid-area: title7v;}
          div#title8v {grid-area: title8v;}
          div#title9v {grid-area: title9v;}
          div#title10v {grid-area: title10v;}
  
          div#title1h {grid-area: title1h;}
          div#title2h {grid-area: title2h;}
          div#title3h {grid-area: title3h;}
          div#title4h {grid-area: title4h;}
          div#title5h {grid-area: title5h;}
          div#title6h {grid-area: title6h;}
          div#title7h {grid-area: title7h;}
          div#title8h {grid-area: title8h;}
          div#title9h {grid-area: title9h;}
          div#title10h {grid-area: title10h;}
  
          div#v1h1 {grid-area: v1h1;}
          div#v1h2 {grid-area: v1h2;}
          div#v1h3 {grid-area: v1h3;}
          div#v1h4 {grid-area: v1h4;}
          div#v1h5 {grid-area: v1h5;}
          div#v1h6 {grid-area: v1h6;}
          div#v1h7 {grid-area: v1h7;}
          div#v1h8 {grid-area: v1h8;}
          div#v1h9 {grid-area: v1h9;}
          div#v1h10 {grid-area: v1h10;}
  
          div#v2h1 {grid-area: v2h1;}
          div#v2h2 {grid-area: v2h2;}
          div#v2h3 {grid-area: v2h3;}
          div#v2h4 {grid-area: v2h4;}
          div#v2h5 {grid-area: v2h5;}
          div#v2h6 {grid-area: v2h6;}
          div#v2h7 {grid-area: v2h7;}
          div#v2h8 {grid-area: v2h8;}
          div#v2h9 {grid-area: v2h9;}
          div#v2h10 {grid-area: v2h10;}
  
          div#v3h1 {grid-area: v3h1;}
          div#v3h2 {grid-area: v3h2;}
          div#v3h3 {grid-area: v3h3;}
          div#v3h4 {grid-area: v3h4;}
          div#v3h5 {grid-area: v3h5;}
          div#v3h6 {grid-area: v3h6;}
          div#v3h7 {grid-area: v3h7;}
          div#v3h8 {grid-area: v3h8;}
          div#v3h9 {grid-area: v3h9;}
          div#v3h10 {grid-area: v3h10;}
  
          div#v4h1 {grid-area: v4h1;}
          div#v4h2 {grid-area: v4h2;}
          div#v4h3 {grid-area: v4h3;}
          div#v4h4 {grid-area: v4h4;}
          div#v4h5 {grid-area: v4h5;}
          div#v4h6 {grid-area: v4h6;}
          div#v4h7 {grid-area: v4h7;}
          div#v4h8 {grid-area: v4h8;}
          div#v4h9 {grid-area: v4h9;}
          div#v4h10 {grid-area: v4h10;}
  
          div#v5h1 {grid-area: v5h1;}
          div#v5h2 {grid-area: v5h2;}
          div#v5h3 {grid-area: v5h3;}
          div#v5h4 {grid-area: v5h4;}
          div#v5h5 {grid-area: v5h5;}
          div#v5h6 {grid-area: v5h6;}
          div#v5h7 {grid-area: v5h7;}
          div#v5h8 {grid-area: v5h8;}
          div#v5h9 {grid-area: v5h9;}
          div#v5h10 {grid-area: v5h10;}
  
          div#v6h1 {grid-area: v6h1;}
          div#v6h2 {grid-area: v6h2;}
          div#v6h3 {grid-area: v6h3;}
          div#v6h4 {grid-area: v6h4;}
          div#v6h5 {grid-area: v6h5;}
          div#v6h6 {grid-area: v6h6;}
          div#v6h7 {grid-area: v6h7;}
          div#v6h8 {grid-area: v6h8;}
          div#v6h9 {grid-area: v6h9;}
          div#v6h10 {grid-area: v6h10;}
  
          div#v7h1 {grid-area: v7h1;}
          div#v7h2 {grid-area: v7h2;}
          div#v7h3 {grid-area: v7h3;}
          div#v7h4 {grid-area: v7h4;}
          div#v7h5 {grid-area: v7h5;}
          div#v7h6 {grid-area: v7h6;}
          div#v7h7 {grid-area: v7h7;}
          div#v7h8 {grid-area: v7h8;}
          div#v7h9 {grid-area: v7h9;}
          div#v7h10 {grid-area: v7h10;}
  
          div#v8h1 {grid-area: v8h1;}
          div#v8h2 {grid-area: v8h2;}
          div#v8h3 {grid-area: v8h3;}
          div#v8h4 {grid-area: v8h4;}
          div#v8h5 {grid-area: v8h5;}
          div#v8h6 {grid-area: v8h6;}
          div#v8h7 {grid-area: v8h7;}
          div#v8h8 {grid-area: v8h8;}
          div#v8h9 {grid-area: v8h9;}
          div#v8h10 {grid-area: v8h10;}
  
          div#v9h1 {grid-area: v9h1;}
          div#v9h2 {grid-area: v9h2;}
          div#v9h3 {grid-area: v9h3;}
          div#v9h4 {grid-area: v9h4;}
          div#v9h5 {grid-area: v9h5;}
          div#v9h6 {grid-area: v9h6;}
          div#v9h7 {grid-area: v9h7;}
          div#v9h8 {grid-area: v9h8;}
          div#v9h9 {grid-area: v9h9;}
          div#v9h10 {grid-area: v9h10;}
  
          div#v10h1 {grid-area: v10h1;}
          div#v10h2 {grid-area: v10h2;}
          div#v10h3 {grid-area: v10h3;}
          div#v10h4 {grid-area: v10h4;}
          div#v10h5 {grid-area: v10h5;}
          div#v10h6 {grid-area: v10h6;}
          div#v10h7 {grid-area: v10h7;}
          div#v10h8 {grid-area: v10h8;}
          div#v10h9 {grid-area: v10h9;}
          div#v10h10 {grid-area: v10h10;}
      }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="covariance"&gt;
      &lt;!--Vertical titles--&gt;
      &lt;div class="title vertical" id="title1v"&gt;Entry 1&lt;/div&gt;
      &lt;div class="title vertical" id="title2v"&gt;Entry 2&lt;/div&gt;
      &lt;div class="title vertical" id="title3v"&gt;Entry 3&lt;/div&gt;
      &lt;div class="title vertical" id="title4v"&gt;Entry 4&lt;/div&gt;
      &lt;div class="title vertical" id="title5v"&gt;Entry 5&lt;/div&gt;
      &lt;div class="title vertical" id="title6v"&gt;Entry 6&lt;/div&gt;
      &lt;div class="title vertical" id="title7v"&gt;Entry 7&lt;/div&gt;
      &lt;div class="title vertical" id="title8v"&gt;Entry 8&lt;/div&gt;
      &lt;div class="title vertical" id="title9v"&gt;Entry 9&lt;/div&gt;
      &lt;div class="title vertical" id="title10v"&gt;Entry 10&lt;/div&gt;
      
      &lt;!--Horizontal titles--&gt;
      &lt;div class="title horizontal" id="title1h"&gt;Entry 1&lt;/div&gt;
      &lt;div class="title horizontal" id="title2h"&gt;Entry 2&lt;/div&gt;
      &lt;div class="title horizontal" id="title3h"&gt;Entry 3&lt;/div&gt;
      &lt;div class="title horizontal" id="title4h"&gt;Entry 4&lt;/div&gt;
      &lt;div class="title horizontal" id="title5h"&gt;Entry 5&lt;/div&gt;
      &lt;div class="title horizontal" id="title6h"&gt;Entry 6&lt;/div&gt;
      &lt;div class="title horizontal" id="title7h"&gt;Entry 7&lt;/div&gt;
      &lt;div class="title horizontal" id="title8h"&gt;Entry 8&lt;/div&gt;
      &lt;div class="title horizontal" id="title9h"&gt;Entry 9&lt;/div&gt;
      &lt;div class="title horizontal" id="title10h"&gt;Entry 10&lt;/div&gt;
      
      &lt;!--entries--&gt;
      &lt;div class="entry" id="v1h1"&gt;1.1&lt;/div&gt;
      &lt;div class="entry" id="v1h2"&gt;1.2&lt;/div&gt;
      &lt;div class="entry" id="v1h3"&gt;1.3&lt;/div&gt;
      &lt;div class="entry" id="v1h4"&gt;1.4&lt;/div&gt;
      &lt;div class="entry" id="v1h5"&gt;1.5&lt;/div&gt;
      &lt;div class="entry" id="v1h6"&gt;1.6&lt;/div&gt;
      &lt;div class="entry" id="v1h7"&gt;1.7&lt;/div&gt;
      &lt;div class="entry" id="v1h8"&gt;1.8&lt;/div&gt;
      &lt;div class="entry" id="v1h9"&gt;1.9&lt;/div&gt;
      &lt;div class="entry" id="v1h10"&gt;1.10&lt;/div&gt;
  
      &lt;div class="entry" id="v2h1"&gt;2.1&lt;/div&gt;
      &lt;div class="entry" id="v2h2"&gt;2.2&lt;/div&gt;
      &lt;div class="entry" id="v2h3"&gt;2.3&lt;/div&gt;
      &lt;div class="entry" id="v2h4"&gt;2.4&lt;/div&gt;
      &lt;div class="entry" id="v2h5"&gt;2.5&lt;/div&gt;
      &lt;div class="entry" id="v2h6"&gt;2.6&lt;/div&gt;
      &lt;div class="entry" id="v2h7"&gt;2.7&lt;/div&gt;
      &lt;div class="entry" id="v2h8"&gt;2.8&lt;/div&gt;
      &lt;div class="entry" id="v2h9"&gt;2.9&lt;/div&gt;
      &lt;div class="entry" id="v2h10"&gt;2.10&lt;/div&gt;
  
      &lt;div class="entry" id="v3h1"&gt;3.1&lt;/div&gt;
      &lt;div class="entry" id="v3h2"&gt;3.2&lt;/div&gt;
      &lt;div class="entry" id="v3h3"&gt;3.3&lt;/div&gt;
      &lt;div class="entry" id="v3h4"&gt;3.4&lt;/div&gt;
      &lt;div class="entry" id="v3h5"&gt;3.5&lt;/div&gt;
      &lt;div class="entry" id="v3h6"&gt;3.6&lt;/div&gt;
      &lt;div class="entry" id="v3h7"&gt;3.7&lt;/div&gt;
      &lt;div class="entry" id="v3h8"&gt;3.8&lt;/div&gt;
      &lt;div class="entry" id="v3h9"&gt;3.9&lt;/div&gt;
      &lt;div class="entry" id="v3h10"&gt;3.10&lt;/div&gt;
  
      &lt;div class="entry" id="v4h1"&gt;4.1&lt;/div&gt;
      &lt;div class="entry" id="v4h2"&gt;4.2&lt;/div&gt;
      &lt;div class="entry" id="v4h3"&gt;4.3&lt;/div&gt;
      &lt;div class="entry" id="v4h4"&gt;4.4&lt;/div&gt;
      &lt;div class="entry" id="v4h5"&gt;4.5&lt;/div&gt;
      &lt;div class="entry" id="v4h6"&gt;4.6&lt;/div&gt;
      &lt;div class="entry" id="v4h7"&gt;4.7&lt;/div&gt;
      &lt;div class="entry" id="v4h8"&gt;4.8&lt;/div&gt;
      &lt;div class="entry" id="v4h9"&gt;4.9&lt;/div&gt;
      &lt;div class="entry" id="v4h10"&gt;4.10&lt;/div&gt;
  
      &lt;div class="entry" id="v5h1"&gt;5.1&lt;/div&gt;
      &lt;div class="entry" id="v5h2"&gt;5.2&lt;/div&gt;
      &lt;div class="entry" id="v5h3"&gt;5.3&lt;/div&gt;
      &lt;div class="entry" id="v5h4"&gt;5.4&lt;/div&gt;
      &lt;div class="entry" id="v5h5"&gt;5.5&lt;/div&gt;
      &lt;div class="entry" id="v5h6"&gt;5.6&lt;/div&gt;
      &lt;div class="entry" id="v5h7"&gt;5.7&lt;/div&gt;
      &lt;div class="entry" id="v5h8"&gt;5.8&lt;/div&gt;
      &lt;div class="entry" id="v5h9"&gt;5.9&lt;/div&gt;
      &lt;div class="entry" id="v5h10"&gt;5.10&lt;/div&gt;
  
      &lt;div class="entry" id="v6h1"&gt;6.1&lt;/div&gt;
      &lt;div class="entry" id="v6h2"&gt;6.2&lt;/div&gt;
      &lt;div class="entry" id="v6h3"&gt;6.3&lt;/div&gt;
      &lt;div class="entry" id="v6h4"&gt;6.4&lt;/div&gt;
      &lt;div class="entry" id="v6h5"&gt;6.5&lt;/div&gt;
      &lt;div class="entry" id="v6h6"&gt;6.6&lt;/div&gt;
      &lt;div class="entry" id="v6h7"&gt;6.7&lt;/div&gt;
      &lt;div class="entry" id="v6h8"&gt;6.8&lt;/div&gt;
      &lt;div class="entry" id="v6h9"&gt;6.9&lt;/div&gt;
      &lt;div class="entry" id="v6h10"&gt;6.10&lt;/div&gt;
  
      &lt;div class="entry" id="v7h1"&gt;7.1&lt;/div&gt;
      &lt;div class="entry" id="v7h2"&gt;7.2&lt;/div&gt;
      &lt;div class="entry" id="v7h3"&gt;7.3&lt;/div&gt;
      &lt;div class="entry" id="v7h4"&gt;7.4&lt;/div&gt;
      &lt;div class="entry" id="v7h5"&gt;7.5&lt;/div&gt;
      &lt;div class="entry" id="v7h6"&gt;7.6&lt;/div&gt;
      &lt;div class="entry" id="v7h7"&gt;7.7&lt;/div&gt;
      &lt;div class="entry" id="v7h8"&gt;7.8&lt;/div&gt;
      &lt;div class="entry" id="v7h9"&gt;7.9&lt;/div&gt;
      &lt;div class="entry" id="v7h10"&gt;7.10&lt;/div&gt;
  
      &lt;div class="entry" id="v8h1"&gt;8.1&lt;/div&gt;
      &lt;div class="entry" id="v8h2"&gt;8.2&lt;/div&gt;
      &lt;div class="entry" id="v8h3"&gt;8.3&lt;/div&gt;
      &lt;div class="entry" id="v8h4"&gt;8.4&lt;/div&gt;
      &lt;div class="entry" id="v8h5"&gt;8.5&lt;/div&gt;
      &lt;div class="entry" id="v8h6"&gt;8.6&lt;/div&gt;
      &lt;div class="entry" id="v8h7"&gt;8.7&lt;/div&gt;
      &lt;div class="entry" id="v8h8"&gt;8.8&lt;/div&gt;
      &lt;div class="entry" id="v8h9"&gt;8.9&lt;/div&gt;
      &lt;div class="entry" id="v8h10"&gt;8.10&lt;/div&gt;
  
      &lt;div class="entry" id="v9h1"&gt;9.1&lt;/div&gt;
      &lt;div class="entry" id="v9h2"&gt;9.2&lt;/div&gt;
      &lt;div class="entry" id="v9h3"&gt;9.3&lt;/div&gt;
      &lt;div class="entry" id="v9h4"&gt;9.4&lt;/div&gt;
      &lt;div class="entry" id="v9h5"&gt;9.5&lt;/div&gt;
      &lt;div class="entry" id="v9h6"&gt;9.6&lt;/div&gt;
      &lt;div class="entry" id="v9h7"&gt;9.7&lt;/div&gt;
      &lt;div class="entry" id="v9h8"&gt;9.8&lt;/div&gt;
      &lt;div class="entry" id="v9h9"&gt;9.9&lt;/div&gt;
      &lt;div class="entry" id="v9h10"&gt;9.10&lt;/div&gt;
  
      &lt;div class="entry" id="v10h1"&gt;10.1&lt;/div&gt;
      &lt;div class="entry" id="v10h2"&gt;10.2&lt;/div&gt;
      &lt;div class="entry" id="v10h3"&gt;10.3&lt;/div&gt;
      &lt;div class="entry" id="v10h4"&gt;10.4&lt;/div&gt;
      &lt;div class="entry" id="v10h5"&gt;10.5&lt;/div&gt;
      &lt;div class="entry" id="v10h6"&gt;10.6&lt;/div&gt;
      &lt;div class="entry" id="v10h7"&gt;10.7&lt;/div&gt;
      &lt;div class="entry" id="v10h8"&gt;10.8&lt;/div&gt;
      &lt;div class="entry" id="v10h9"&gt;10.9&lt;/div&gt;
      &lt;div class="entry" id="v10h10"&gt;10.10&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>.</p>