JSFiddle - React, Tailwind, and code Playground

by Daniel Cheung

HTML

<div class="choice">
  <div class="cont left">
    <button type="button" class="left">Semaine</button>
    <button type="button" class="right">Mois</button>
  </div>
</div>

CSS

* {
  box-sizing: border-box;
  margin:0;
  padding:0;
}

span {
  list-style-type: none;
}

span a {
  text-decoration: none;
}

.cont {
  background-color: white;
  width: 100%;
  padding: 5px;
  border-radius: 20px;
}

.cont::before {
  content: " ";
  background:#B7D4E1;
  width: 100px;
  height:40px;
  border-radius: 20px;
  position:absolute;
  top:5px;
  left:5px;
  transition: all 0.2s ease-out;
}

.choice {
  float: left;
  margin-right: 1px;
}

.choice button {
  color: #000;
  width: 100px;
  height:40px;
  border:0;
  display:inline-block;
  text-align: center;
  background: transparent;
  transition: all 0.4s linear;
  border-radius: 20px;
  position:relative;
}

.choice .cont.right::before {
  transform: translate3d(105px,0,0);
}

JavaScript

$(".choice button").click(function() {
	$(this).closest(".cont").removeClass("left right");
  if ($(this).hasClass("left")) {
  	$(this).closest(".cont").addClass("left");
  } else {
  	$(this).closest(".cont").addClass("right");
  }
})