JSFiddle - React, Tailwind, and code Playground

by Ercan Cicek

HTML

<div id="two-choice-item">
  <div class="box first-box" onClick="activateBox('first');">
    <span>placeholder</span>
  </div>
  <div class="vertical-divider"></div>
  <div class="box second-box" onClick="activateBox('second');">
    <span>placeholder</span>
  </div>
  <div id="fill"></div>
</div>

SCSS

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400&display=swap');

#two-choice-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  grid-column-gap: 0px;
  grid-row-gap: 0px;
  width: 343px;
  border: 1px solid #D6D6D6;
  border-radius: 8px;
  &.first-active {
    > #fill {
      width: calc(50% - 1px);
      border-top-left-radius: 8px;
      border-bottom-left-radius: 8px;
      left: 0;
    }
    > .first-box {
      > span {
        color: #F8F8FDE5;
      }
    }
    > .second-box {
      > span {
        color: #0B103559;
      }
    }
  }
  &.second-active {
    > #fill {
      width: calc(50% - 1px);
      border-top-right-radius: 8px;
      border-bottom-right-radius: 8px;
      right: 0;
    }    
    > .first-box {
      > span {
        color: #0B103559;
      }
    }
    > .second-box {
      > span {
        color: #F8F8FDE5;
      }
    }
  }
  > .box {
    z-index: 2;
    display: flex;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: pointer;
    > span {
      width: 100%;
      padding-top: 32px;
      padding-bottom: 32px;
      font-family: 'Poppins', sans-serif;
      font-style: normal;
      font-weight: 300;
      font-size: 16px;
      line-height: 24px;
      letter-spacing: 0.02em;
      transition: color 0.2s ease-in-out;
    }
    &.first-box {
      > span {
        padding-right: 12px;
        padding-left: 8px;
        text-align: center;
      }
    }
    &.second-box {
      > span {
        padding-right: 8px;
        padding-left: 12px;
        text-align: center;
      }
    }
  }
  > .vertical-divider {
    width: 1px;
    height: 100%;
    background-color: #D6D6D6;
  }
  > #fill {
    z-index: 1;
    position: absolute;
    top: 0;
    left: 50%;
    width: 1px;
    height: 100%;
    background-color: #2A729D;
    transition: left 0.2s ease-in-out, width 0.2s ease-in-out, border-radius 0.2s ease-in-out;
  }
}

JavaScript

function activateBox(num) {
	$("#two-choice-item").removeClass("first-active second-active");
	$("#two-choice-item").addClass(num + "-active");
}