Making the content inside grid items equal height in CSS Grid

后端 未结 3 1403
孤街浪徒
孤街浪徒 2021-01-18 08:01

I am trying to figure out how to get two columns of my grid the same height. Here is what I am after:

xxxxxxxxxxxxxxxxx   xxxxxxxxxxxxxxxxxxx 
x qqqqqqq
3条回答
  •  轮回少年
    2021-01-18 08:27

    Those grid items are already the same height. They are both the height of the second row, which is 1fr, as defined by grid-template-rows on the grid container.

    If you put a border around those two items (.companyInfoContainer & .contactInfoContainer), you'll see what I mean.

    revised demo

    It seems that you want the bordered children of the grid items (.companyInfoBox and .contactInfoBox) to consume all available height.

    Since the grid items are not also grid containers, you can't use grid properties on the children.

    An easy and efficient solution would be to make the grid items flex containers. Then you can apply flex properties to the children, which can make them consume free space.

    .companyInfoContainer {
       display: flex;
       flex-direction: column;
    }
    
    .companyInfoBox {
       flex: 1;
     }
    
    .contactInfoContainer {
      display: flex;
      flex-direction: column;
    }
    
    .contactInfoBox {
       flex: 1
    }
    

    revised demo

    More details: Descendant element not responding to grid properties

提交回复
热议问题