Search code examples
cssalignmentcss-grid

CSS grid: How to align baseline of spanned row to the last row of other columns


I want to align the baseline of a to c.

#grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  align-items: baseline;
}
#a{
  grid-row: 1 / span 2;
  grid-column: 1;
  padding: 8px;
  background: red;
}
#b{
  grid-row: 1;
  grid-column: 2;
  background: yellow;
}
#c{
  grid-row: 2;
  grid-column: 2;
  background: blue;
}
<div id="grid">
  <div id="a">aaaaa</div>
  <div id="b">bbbbb</div>
  <div id="c">ccccc</div>
</div>

I tried making the outer grid a single row and wrap b and c into a single div with inline-whatever, but a still always align to b instead of c.

#grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  align-items: baseline;
}
#a{
  grid-row: 1;
  grid-column: 1;
  padding:8px;
  background:red;
}
#d{
  display:inline-block;
  grid-row: 1;
  grid-column: 2;
}
#b{
  background:yellow;
}
#c{
  background:blue
}
<div id="grid">
  <div id="a">aaaaa</div>
  <div id="d">
    <div id="b">bbbbb</div>
    <div id="c">ccccc</div>
  </div>
</div>

How to make a align baseline to c?


Solution

  • I believe you want to declare align-items: last baseline

    Can I Use align-items: last baseline? is showing 85% global support.

    Specification jargon can be found at Flex Container Baselines

    #grid{
      display: grid;
      grid-template-columns: 1fr 1fr;
      align-items: last baseline;
    }
    
    #a {
      grid-row: span 2;
      padding: 8px;
      background: red;
    }
    #b {
      background: yellow;
    }
    
    #c {
      background: blue;
    }
    <div id="grid">
      <div id="a">aaaaa</div>
      <div id="b">bbbbb</div>
      <div id="c">ccccc</div>
    </div>