skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    Since last baseline is still relatively new (I am using Electron 19 which does not support), I am looking for alternatives. Referring to this SO post about flex, turns out I have to wrap the inline-block into yet another container.

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


  2. 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>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search