DEV Community

Cover image for CSSBattle | #20 Ticket
Nazmuz Shakib Pranto
Nazmuz Shakib Pranto

Posted on

CSSBattle | #20 Ticket

Welcome to CSSBattle Challenges!

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


Challenge:

Ticket Challenge


Solution:

<div class="container">
  <div class="ticket-transparent">
    <div class="round-dot lg top-left"></div>
    <div class="round-dot lg bottom-left"></div>
    <div class="round-dot sm top-center"></div>
    <div class="round-dot sm bottom-center"></div>
    <div class="round-dot lg top-right"></div>
    <div class="round-dot lg bottom-right"></div>
    <div class="ticket">
      <div class="yellow-side"></div>
      <div class="orange-side"></div>
    </div>
  </div>
</div>

<style>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  .container {
    width: 100vw;
    height: 100vh;
    background: #62306d;
    position: relative;
  }
  .ticket,
  .ticket-transparent {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 100px;
  }
  .ticket {
    display: flex;
  }
  .yellow-side {
    width: 70%;
    background: #f7ec7d;
  }
  .orange-side {
    width: 30%;
    background: #e38f66;
  }
  .round-dot {
    position: absolute;
    z-index: 10;
    background: #62306d;
    border-radius: 50%;
  }
  .lg {
    width: 40px;
    height: 40px;
  }
  .sm {
    width: 20px;
    height: 20px;
  }
  .top-left {
    transform: translate(-20px, -20px);
  }
  .bottom-left {
    bottom: 0;
    left: 0;
    transform: translate(-20px, 20px);
  }
  .top-center {
    top: 0;
    left: 70%;
    transform: translate(-10px, -10px);
  }
  .bottom-center {
    bottom: 0;
    left: 70%;
    transform: translate(-10px, 10px);
  }
  .top-right {
    right: 0;
    transform: translate(20px, -20px);
  }
  .bottom-right {
    bottom: 0;
    right: 0;
    transform: translate(20px, 20px);
  }
</style>
Enter fullscreen mode Exit fullscreen mode

Key Takeaway(s):

  • using transparent element behind the scenes to control position of children elements, so in this case, .ticket-transparent is just a transparent placeholder to position all the dots in the correct places

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

Top comments (1)

Collapse
 
urvesh1121 profile image
URVESH RADADIYA

body{
background:#62306D;
display:flex;
align-items:center;
justify-content:center;
}
#rec1 {
width: 60px;
height: 100px;
background:#E38F66;
}
#rec2 {
width: 140px;
height: 100px;
background:#F7EC7D;
}
#cir{
width:40px;
height:40px;
background:#62306D;
border-radius:50%;
position: absolute;
top:80;
right:280;
box-shadow: 200px 0 #62306D,0px 100px #62306D,200px 100px #62306D;
}
#cir2{
width:20px;
height:20px;
background:#62306D;
border-radius:50%;
position: absolute;
top:90;
left:230;
box-shadow:0 100px #62306D;
}