title: CSS Grid vs dynamic definition list autoplacement
body: <p><strong>Disclaimer:</strong> According to the <a href="https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element" rel="nofollow noreferrer">spec</a>, one could wrap <code>dt + dd</code> pairs into a <code>div</code>, which would allow me to trivially solve my problem using either <code>float</code> and <code>clear</code>, flexbox or even CSS grid.</p>
  
  <p>There are also alternatives like <a href="https://stackoverflow.com/a/49336248/1798341">this</a> that wraps each group of 2 <code>dt + dd</code> pairs into separate <code>ul</code> tags. This also works, even though it's not 100% semantically accurate.</p>
  
  <p>Now what I am really trying to do is to find a solution for the problem using CSS grid, without resorting to any of the above techniques.</p>
  
  <hr>
  
  <p>I have the following structure in my HTML:</p>
  
  <pre><code>dl
    dt
    dd
  
    dt
    dd
  
    dt
    dd
  
    dt
    dd
  
    ...
  </code></pre>
  
  <p>I want to display them grouped in 2 columns and 2 rows like this:</p>
  
  <pre><code>dt    dt
  dd    dd
  
  dt    dt
  dd    dd
  
  ..    ..
  </code></pre>
  
  <p>I managed to find a solution for the case when I have 4 pairs and want to display them in a 2x2 grid:</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>body {
    font-family: sans-serif;
  }
  
  dl {
    display: grid;
    grid-gap: 0 1rem;
    grid-template-columns: [col] 1fr [col] 1fr [col];
    grid-template-rows: repeat(auto-fill, 1fr);
    text-align: center;
  }
  
  dt {
    padding: 0.25rem 1rem;
    background: lightcoral;
  }
  
  dt:nth-of-type(2n + 1) {
    counter-increment: left;
    grid-column: col 1 / span 1;
  }
  
  dt:nth-of-type(2n) {
    counter-increment: right;
    grid-column: col 2 / span 1;
  }
  
  
  /* Comment out the following 2 selectors to see the "automatic behavior */
  
  dt:nth-of-type(2) {
    grid-row: 1;
  }
  
  dt:nth-of-type(4) {
    grid-row: 3;
  }
  
  
  /* /Comment out */
  
  dd {
    margin: 0 0 1rem;
    padding: 0.25rem 1rem;
    background: lightcyan;
  }
  
  dd:nth-last-of-type(-n + 2) {
    margin-bottom: 0;
  }
  
  dd:nth-of-type(2n + 1) {
    grid-column: col 1 / span 1;
  }
  
  dd:nth-of-type(2n) {
    grid-column: col 2 / span 1;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;title&gt;Parcel Sandbox&lt;/title&gt;
    &lt;meta charset="UTF-8" /&gt;
    &lt;link rel="stylesheet" type="text/css" href="src/styles.css" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;div id="app"&gt;
      &lt;dl&gt;
        &lt;dt&gt;Item 1&lt;/dt&gt;
        &lt;dd&gt;Nunc ut quam at sem vehicula hendrerit sed vitae risus&lt;/dd&gt;
        &lt;dt&gt;Item 2&lt;/dt&gt;
        &lt;dd&gt;
          uisque a maximus mauris. Quisque metus quam, auctor ac porttitor.
        &lt;/dd&gt;
        &lt;dt&gt;Item 3&lt;/dt&gt;
        &lt;dd&gt;
          Aliquam varius est ac lectus malesuada, a sagittis arcu laoreet.
        &lt;/dd&gt;
        &lt;dt&gt;Item 4&lt;/dt&gt;
        &lt;dd&gt;Etiam et sapien at mi ultrices maximus vitae vel arcu.&lt;/dd&gt;
      &lt;/dl&gt;
    &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>However, that only works because I'm manually defining the row in which specific <code>dt</code> elements should sit on:</p>
  
  <pre class="lang-css prettyprint-override"><code>dt:nth-of-type(2) {
    grid-row: 1;
  }
  
  dt:nth-of-type(4) {
    grid-row: 3;
  }
  </code></pre>
  
  <p>Without this I would get:</p>
  
  <p><img src="https://i.stack.imgur.com/S1LhX.png" alt="Grid Autoplacement Issue"></p>
  
  <p>The row placement for the items on the right is off by 1.</p>
  
  <p>Is there a way to "shift" the value of <code>grid-row</code> by <code>-1</code> in a general fashion?</p>
  
  <p>I also tried to pair <code>grid-row</code> value with <code>counter</code>, but it looks like this is unsupported.</p>