title: How to align columns in nested HTML using CSS grid
body: <p>I need to use a grid, but my columns are not direct children of the grid. The grid has two columns:</p>
  
  <ol>
  <li>Column 1 contains the label.</li>
  <li>Column 2 contains the input box.</li>
  </ol>
  
  <p>The label column should be as large (but not larger) than the largest column. The input column should use all remaining space. I attempted the following CSS/HTML combo.</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>* {
    border: 1px solid black;
    background: #2222;
  }
  
  .container {
    display: grid;
    width: 550px;
    grid-gap: 10px;
    grid-template-rows: [a] auto [b] auto [c] auto;
    grid-template-columns: [label] auto [input] 1fr;
    align-items: stretch;
  }
  
  label { grid-column-start: label; }
  input { grid-column-start: input; }
  
  .a { grid-row-start: a; }
  .b { grid-row-start: b; }
  .c { grid-row-start: c; }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt;
    &lt;div class="a"&gt;
      &lt;label&gt;A&lt;/label&gt;
      &lt;input&gt;
    &lt;/div&gt;
    &lt;div class="b"&gt;
      &lt;label&gt;Label B&lt;/label&gt;
      &lt;input&gt;
    &lt;/div&gt;
    &lt;div class="c"&gt;
      &lt;label&gt;Longest C label&lt;/label&gt;
      &lt;input&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I understand that the <code>grid-column-start</code> isn't used, because the elements are not direct children of the grid. But how can I accomplish this functionality without hardcoding the label width or use Javascript?</p>
  
  <p>Using multiple grids (one per row) would be fine, but I would need to synchronized the widths of the first column. I have read about <a href="https://www.smashingmagazine.com/2018/07/css-grid-2/" rel="nofollow noreferrer">subgrids</a>, but it's not implemented by any major browser yet. Do I have other alternatives to solve this issue?</p>