Grid of responsive squares

前端 未结 4 503
一生所求
一生所求 2020-11-22 03:35

I\'m wondering how I would go about creating a layout with responsive squares. Each square would have vertically and horizontally aligned c

4条回答
  •  情深已故
    2020-11-22 04:04

    You could use vw (view-width) units, which would make the squares responsive according to the width of the screen.

    A quick mock-up of this would be:

    html,
    body {
      margin: 0;
      padding: 0;
    }
    div {
      height: 25vw;
      width: 25vw;
      background: tomato;
      display: inline-block;
      text-align: center;
      line-height: 25vw;
      font-size: 20vw;
      margin-right: -4px;
      position: relative;
    }
    /*demo only*/
    
    div:before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      height: inherit;
      width: inherit;
      background: rgba(200, 200, 200, 0.6);
      transition: all 0.4s;
    }
    div:hover:before {
      background: rgba(200, 200, 200, 0);
    }
    1
    2
    3
    4
    5
    6
    7
    8

提交回复
热议问题