<form class="form">
<h2>Is this awesome?</h2>
<div class="switch-field">
<input type="radio" id="radio-one" name="switch-one" value="yes" checked/>
<label for="radio-one">Yes</label>
<input type="radio" id="radio-two" name="switch-one" value="no" />
<label for="radio-two">No</label>
</div>
<h2>Three fields? Sure.</h2>
<div class="switch-field">
<input type="radio" id="radio-three" name="switch-two" value="yes" checked/>
<label for="radio-three">One</label>
<input type="radio" id="radio-four" name="switch-two" value="maybe" />
<label for="radio-four">Two</label>
<input type="radio" id="radio-five" name="switch-two" value="no" />
<label for="radio-five">Three</label>
</div>
<h2>I'm ugly.</h2>
<div class="regular-field">
<input type="radio" id="radio-six" name="notaswitch-one" value="yes" checked/>
<label for="radio-six">Boring</label>
<input type="radio" id="radio-seven" name="notaswitch-one" value="maybe" />
<label for="radio-seven">Generic</label>
<input type="radio" id="radio-eight" name="notaswitch-one" value="no" />
<label for="radio-eight">Confusing</label>
</div>
<h2>So am I.</h2>
<div class="regular-field">
<input type="radio" id="radio-nine" name="notaswitch-two" value="yes" checked/>
<label for="radio-nine">This works</label><br />
<input type="radio" id="radio-ten" name="notaswitch-two" value="maybe" />
<label for="radio-ten">I'm used to it</label><br />
<input type="radio" id="radio-eleven" name="notaswitch-two" value="no" />
<label for="radio-eleven">I have no flavor</label><br />
</div>
</form>
.switch-field {
display: flex;
margin-bottom: 36px;
overflow: hidden;
}
.switch-field input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}
.switch-field label {
background-color: #e4e4e4;
color: rgba(0, 0, 0, 0.6);
font-size: 14px;
line-height: 1;
text-align: center;
padding: 8px 16px;
margin-right: -1px;
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
transition: all 0.1s ease-in-out;
}
.switch-field label:hover {
cursor: pointer;
}
.switch-field input:checked + label {
background-color: #a5dc86;
box-shadow: none;
}
.switch-field label:first-of-type {
border-radius: 4px 0 0 4px;
}
.switch-field label:last-of-type {
border-radius: 0 4px 4px 0;
}
/* This is just for CodePen. */
.form {
max-width: 600px;
font-family: "Lucida Grande", Tahoma, Verdana, sans-serif;
font-weight: normal;
line-height: 1.625;
margin: 8px auto;
padding: 16px;
}
h2 {
font-size: 18px;
margin-bottom: 8px;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.