CSS flex and grid using Cssbattles challange.
Tags: mobile, reactnative, javascript, codereview
Published: 2023-09-13 23:07:08

In this article, we'd solve a [CSS battle](https://cssbattle.dev/) challenge [[click here for this exact challenge](https://cssbattle.dev/play/gK8G0EfMHBHjUEe8qHfr)]. 


![CSS battle start screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ktlfh2nm5vz51k24j3f.png)

To solve this challenge, we'd split the process in 3 stages. 


#1 the background
The colours to be used in here are already provided, so our duty is to use them appropriately. For this design, our background colour is "#DA30D4". To handle the background, we'd use the "body" tag to handle the background.
We'd be using flex to make sure that everything is centred, both vertically and horizontally.

```
body{
    background-color: #DA30D4;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
  }
```
Add the above styles in the styles tag
![image outcome for the background](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/apfdyl7s3g4066q8hjvn.png)


#2 Create a wrapper that holds the four circles.
In this section, go ahead and add a class name of 'wrapper' in the existing DIV, then 4 children <div>'s within the wrapper DIV.
In this section, we'd use display of grid to efficiently wrap our circles into the columns by using the "grid-template-column" CSS property. There is no need to use the width and height property in this section, all we'd be doing is ensure that its children items are centred. Vertically and Horizontally. Then, essentially, add a gap of 20px. This will ensure that the space here is between the columns and the rows is 20px.
Here is the snippet for this section

```
<div class='wrapper'>
  <div class='circle'></div>
  <div class='circle'></div>
  <div class='circle'></div>
  <div class='circle'></div>
</div>
<style>
  body{
    background-color: #DA30D4;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .wrapper{
    display: grid;
    justify-content: center;
    align-items: center;
    grid-template-columns: 1fr 1fr ;
    gap: 20px;
  }
  .circle{
    background-color: #0C0C49;
    width: 100px;
    height: 100px;
    border-radius: 50px;
  }
</style>

```
copy and paste the section for this needed part

#3 the last part of this is the box at the outermost layer. Like, the top level.
For this section, set the position to absolute, this will permit the box to sit over the wrapper as the items have all been assigned to be centred by the body. Change the colour as required, and you've got a catch in your hook

```
<div class='wrapper'>
  <div class='circle'></div>
  <div class='circle'></div>
  <div class='circle'></div>
  <div class='circle'></div>
</div>
<div class='box'></div>
<style>
  body{
    background-color: #DA30D4;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
  }
  .wrapper{
    width: 100px;
    height: 220px;
    display: grid;
    justify-content: center;
    align-items: center;
    grid-template-columns: 1fr 1fr ;
    padding: 1px;
    gap: 20px;
  }
  .circle{
    background-color: #0C0C49;
    width: 100px;
    height: 100px;
    border-radius: 50px;
  }
  .box {
    width: 120px;
    height: 120px;
     background-color: #DA30D4;
    position: absolute;
  } 
</style>

```

Here is the result from this snippet


![final result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qayoe6a4jk17a9uzncd.png)



This is the end of this article.

If you have this final snippets posted in, you are ready to hit the ** _submit and smile at your 100%_ **

![submission result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6coa1q0anz0cdeffym6r.png)


![final score](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ihehjos72neh02ae4jj8.png)


You can also choose to watch me code this live on youtube [here](https://www.youtube.com/watch?v=nPDA2TGnWzI) 
Also do well to drop a like and subscribe, here and on youtube. 
You're done.
Challenge solved and defeated.

Stay tuned for more articles like this, as we go through and debug some bugs and some errors in our day-to-day development. Both simple and complex bugs.
Cheers!!😊