Prevent content from expanding grid items

后端 未结 3 1571
长发绾君心
长发绾君心 2020-11-21 06:32

TL;DR: Is there anything like table-layout: fixed for CSS grids?


I tried to create a year-view calendar with a big 4x3 grid for t

3条回答
  •  一个人的身影
    2020-11-21 06:44

    The existing answers solve most cases. However, I ran into a case where I needed the content of the grid-cell to be overflow: visible. I solved it by absolutely positioning within a wrapper (not ideal, but the best I know), like this:

    
    .month-grid {
      display: grid;
      grid-template: repeat(6, 1fr) / repeat(7, 1fr);
      background: #fff;
      grid-gap: 2px;  
    }
    
    .day-item-wrapper {
      position: relative;
    }
    
    .day-item {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      padding: 10px;
    
      background: rgba(0,0,0,0.1);
    }
    

    https://codepen.io/bjnsn/pen/vYYVPZv

提交回复
热议问题