Make grid item use remaining space like flex item with flex-grow: 1 [duplicate]

时间秒杀一切 提交于 2019-12-06 15:46:35

You could specify the row height with grid-template-rows: min-content auto;, which minimizes the first row and stretches the second.

html,
body {
  height: 100%
}
<div style="display:grid;grid-template-columns:auto;height:100%;grid-template-rows: min-content auto;">
  <div style="background-color:yellow;height:50px"></div>
  <div style="background-color:red;"></div>
</div>

Use grid-template-rows:

<html style="height: 100%">
  <body style="height: 100%">
    <div style="display:grid;grid-template-columns:auto;grid-template-rows: 50px auto; height:100%">
      <div style="background-color:yellow"></div>
      <div style="background-color:red"></div>
    </div>
  </body>
</html>

Note: the html and body need their heights set to 100% because the grid doesn't automatically grow downwards like flex does.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!