DEV Community

Cover image for CSSBattle | #28 Cups & Balls
Nazmuz Shakib Pranto
Nazmuz Shakib Pranto

Posted on

CSSBattle | #28 Cups & Balls

Welcome to CSSBattle Challenges!

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


Challenge:

Cups & Balls Challenge


Solution:

<div class="container">
  <div class="box">
    <div class="ball bg-lemon-ginger"></div>
    <div class="cup bg-yellow-orange"></div>
    <div class="cup bg-lemon-ginger"></div>
    <div class="ball bg-yellow-orange"></div>
    <div class="cup bg-yellow-orange upside-down"></div>
    <div class="ball bg-lemon-ginger "></div>
    <div class="ball bg-yellow-orange"></div>
    <div class="cup bg-lemon-ginger upside-down"></div>
  </div>
</div>

<style>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  .container {
    background: #1A4341;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .bg-yellow-orange {
    background: #F3AC3C;
  }
  .bg-lemon-ginger {
    background: #998235;
  }
  .upside-down {
    transform: rotate(180deg);
  }
  .box {
    width: calc(50px + 50px + 50px + 50px + 60px);
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
  }
  .ball {
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
  .cup {
    width: 50px;
    height: 50px;
    border-top-left-radius: 50px;
    border-top-right-radius: 50px;
  }
</style>
Enter fullscreen mode Exit fullscreen mode

Key Takeaway(s):

  • using display: flex to align items both vertically and horizontally
  • using gap property to create equal spacing between flex children elements

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

Top comments (0)