DEV Community

Cover image for CSSBattle | #7 Leafy Trail
Nazmuz Shakib Pranto
Nazmuz Shakib Pranto

Posted on

CSSBattle | #7 Leafy Trail

Welcome to CSSBattle Challenges!

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


Challenge:

Leafy Trail Challenge


Solution:

<div class="container">
  <div class="leaf left"></div>
  <div class="leaf center"></div>
  <div class="leaf right"></div>
</div>

<style>
  * {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
  }
  .container {
    width: 100%;
    height: 100%;
    background: #0B2429;
    position: relative;
  }
  .leaf {
    width: 150px;
    height: 150px;
    border-top-left-radius: 100px;
    border-bottom-right-radius: 100px;
    position: absolute;
    top: 50%;
    left: 50%;
  }
  .left {
    background: #1A4341;
    transform: translate(calc(-50% + -50px), -50%) 
  }
  .center {
    background: #998235;
    transform: translate(-50%, -50%)
  }
  .right {
    background: #F3AC3C;
    transform: translate(calc(-50% + 50px), -50%);
  }
</style>
Enter fullscreen mode Exit fullscreen mode

Key Takeaway(s):

  • using top: 50% and left: 50% and transform: translate(-50%, -50%) to center absolute positioned elements
  • adjusting border radius properties to create a leaf like element

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

Discussion (0)