DEV Community

Cover image for CSSBattle | #18 Matrix
Nazmuz Shakib Pranto
Nazmuz Shakib Pranto

Posted on

CSSBattle | #18 Matrix

Welcome to CSSBattle Challenges!

In this short article, I go through my solution for CSSBattle - #18 Matrix challenge. Please refer to the code snippet below to get a better insight into my thought processes and the implementation detail.


Challenge:

Matrix Challenge


Solution:

<div class="container">
  <div class="box bg-orange"></div>
  <div class="box bg-lightyellow"></div>
  <div class="box bg-orange"></div>
  <div class="box bg-lightyellow"></div>
  <div class="box bg-lightyellow"></div>
  <div class="box bg-orange"></div>
  <div class="box bg-lightyellow"></div>
  <div class="box bg-orange"></div>
  <div class="box bg-orange"></div>
  <div class="box bg-lightyellow"></div>
  <div class="box bg-orange"></div>
  <div class="box bg-lightyellow"></div>
</div>

<style>
  * {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }
  .container {
    height: 100vh;
    width: 100vw;
    display: grid;
    grid-template-rows: repeat(3, calc(320px / 4));
    grid-template-columns: repeat(4, calc(320px / 4));
    grid-gap: 20px;
    padding: 10px;
    background: #5C434C;
  }
  .box {
    border-top-left-radius: 100%;
  }
  .bg-orange {
    background: #F09462;
  }
  .bg-lightyellow {
    background: #F5D6B4;
  }
</style>
Enter fullscreen mode Exit fullscreen mode

Key Takeaway(s):

  • using display: grid to align contents both horizontally and vertically at the same time
  • using grid-gap property to create equal spacing between all the grid elements

As always, I welcome any feedback or questions regarding the implementation detail of the challenge. Otherwise, I hope this was useful!

Discussion (0)