Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set min-height on the grid-template-column containers [duplicate]

Tags:

html

css

css-grid

I have following problem: if there is content in first container, then the other two without content will be the same height as the first one:

https://jsfiddle.net/tj4hbya5/2/

.grid {
  padding: 5px;
  background: gray;
  display: grid;
  grid-template-columns: auto auto auto;
}
.todo-column {
  min-height: 150px;
  margin: 0 auto;
  width: 90%;
  background: cyan;
  text-align: center;
 }
  
.todo-title {
  color: white;
  font-size: 175%;
  padding: 5px;
  border-bottom: 5px dotted black;
 }
<div class="grid">
  <div class="todo-column">
    <h1 class="todo-title">Aloittamatta</h1>
    <h1>foo</h1>
    <h1>foo</h1>
    <h1>foo</h1>
    <h1>foo</h1>
    <h1>foo</h1>
    <h1>foo</h1>
  </div>
  <div class="todo-column">
    <h1 class="todo-title">Työn alla</h1>
  </div>
  <div class="todo-column">
    <h1 class="todo-title">Valmis</h1>
  </div>
</div>

So, how can I set the default height to be the same on all three containers, but if one of them has some content, then the height will be choosen automatically, while the other two without content stay at min-height?

like image 945
Juska Avatar asked Jan 20 '26 03:01

Juska


1 Answers

Add align-items: self-start; in ".grid" class and set min-height in ".todo-column" class

.grid {
  padding: 5px;
  background: gray;
  display: grid;
  grid-template-columns: auto auto auto;
  align-items:self-start;
}
.todo-column {
  min-height: 150px;
  margin: 0 auto;
  width: 90%;
  background: cyan;
  text-align: center;
 }
  
.todo-title {
  color: white;
  font-size: 175%;
  padding: 5px;
  border-bottom: 5px dotted black;
  min-height: 100px;
 }
<div class="grid">
  <div class="todo-column">
    <h1 class="todo-title">Aloittamatta</h1>
              <h1>foo</h1>
          <h1>foo</h1>
          <h1>foo</h1>
          <h1>foo</h1>
          <h1>foo</h1>
          <h1>foo</h1>
  </div>
  <div class="todo-column">
    <h1 class="todo-title">Työn alla</h1>
  </div>
  <div class="todo-column">
    <h1 class="todo-title">Valmis</h1>
  </div>
</div>
like image 135
Pratik Malvi Avatar answered Jan 22 '26 16:01

Pratik Malvi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!