force css grid container to fill full screen of device

前端 未结 4 1971
孤城傲影
孤城傲影 2021-01-31 01:28

How do I force a css grid container take the full width and height of the device screen for a single page app? Modified example is from Mozilla: Firefox documentation

4条回答
  •  渐次进展
    2021-01-31 01:51

    You can add position: fixed; with top left right bottom 0 attribute, that solution work on older browsers too.

    If you want to embed it, add position: absolute; to the wrapper, and position: relative to the div outside of the wrapper.

    .wrapper {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
    
      display: grid;
      border-style: solid;
      border-color: red;
      grid-template-columns: repeat(3, 1fr);
      grid-template-rows: repeat(3, 1fr);
      grid-gap: 10px;
    }
    .one {
      border-style: solid;
      border-color: blue;
      grid-column: 1 / 3;
      grid-row: 1;
    }
    .two {
      border-style: solid;
      border-color: yellow;
      grid-column: 2 / 4;
      grid-row: 1 / 3;
    }
    .three {
      border-style: solid;
      border-color: violet;
      grid-row: 2 / 5;
      grid-column: 1;
    }
    .four {
      border-style: solid;
      border-color: aqua;
      grid-column: 3;
      grid-row: 3;
    }
    .five {
      border-style: solid;
      border-color: green;
      grid-column: 2;
      grid-row: 4;
    }
    .six {
      border-style: solid;
      border-color: purple;
      grid-column: 3;
      grid-row: 4;
    }
    
    
    One
    Two
    Three
    Four
    Five
    Six

提交回复
热议问题