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!

Top comments (2)

Collapse
 
stevencrocker profile image
Steven Crocker

The solution I came up with, also using grid and nth-child selectors

<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
<style>
  body{
    background: #5c434c;
    margin: 10px;
    display: grid;
    grid: 1fr 1fr 1fr / 80px;
    grid-auto-flow: column;
    gap: 20px;
  }
  i{
    background: #f09462;
    border-radius: 100% 0 0;
  }
  i:nth-child(2n){
    background: #f5d6b4
  }
</style>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
joaaoneto profile image
joaaoneto

body{
margin: 10px 10px;
background: #5C434C;
}
div {
width: 80px;
height: 80px;
background: #F09462;
border-radius: 100% 0 0;
box-shadow: 100px 0 #F5D6B4, 200px 0 #F09462, 300px 0 #F5D6B4, 0 100px #F5D6B4, 100px 100px #F09462, 200px 100px #F5D6B4, 300px 100px #F09462, 0px 200px #F09462, 100px 200px #F5D6B4, 200px 200px #F09462, 300px 200px #F5D6B4
}

it can be also be made just with box-shadows, im just started coding, so im trying this challenges with the most easy for me