JSFiddle - React, Tailwind, and code Playground
by Adam Mendoza
HTML
<div id="Segmented_Control">
<input type="radio" name="Switch" value="All" id="All_Switch" class="Radio_Switch"/>
<input type="radio" name="Switch" value="Favorites" id="Favorites_Switch" class="Radio_Switch"/>
<div id="Selected_Container">
</div> <!-- Selected Container -->
<label for="All_Switch">
<div class="Switch_Containers" id="All_Container">
<p class="Switch_Text" id="All_Text">All</p> <!-- All Switch -->
</div>
</label> <!-- All Switch Label -->
<label for="Favorites_Switch">
<div class="Switch_Containers" id="Favorites_Container">
<p class="Switch_Text" id="Favorites_Text">Favorites</p> <!-- Favorites Switch -->
</div> <!-- Favorites Container -->
</label>
</div> <!-- Segmented Control -->
CSS
* {
font-family: Arial;
font-size: 3vmin;
font-weight: bold;
}
#Segmented_Control {
position: relative;
margin-left: auto;
margin-right: auto;
height: 5vh;
width: 50vw;
background-color: #38d1a9;
border-radius: 5px;
border: 2px solid #38D1A9;
margin-top: 0%;
margin-bottom: 0%;
}
.Radio_Switch {
display: none;
}
.Switch_Text {
margin: 0%;
text-align: center;
position: relative;
top: 25%;
font-size: 3vmin;
font-weight: bold;
transition: color 1s ease;
}
#All_Text {
color: #38D1A9;
}
#Favorites_Text {
color: #FFFFFF;
}
#Selected_Container {
position: absolute;
left: 0%;
top: 0%;
margin: 0%;
background-color: #FFFFFF;
height: 100%;
width: 50%;
border-radius: 5px 0px 0px 5px;
}
.Switch_Containers {
display: inline-block;
margin: 0%;
height: 100%;
width: 50%;
}
#All_Container {
float: left;
}
#Favorites_Container {
float: right;
}
#Favorites_Switch:checked ~ #Selected_Container {
position: absolute;
left: 50%;
transition: all .2s ease;
border-radius: 0px 5px 5px 0px;
}
#Favorites_Switch:checked ~ label #Favorites_Text {
color: #38D1A9;
}
#Favorites_Switch:checked ~ label #All_Text {
color: #FFFFFF;
}
#All_Switch:checked ~ #Selected_Container {
position: absolute;
left: 0%;
transition: all .2s ease;
}