ラジオボタン風のチェックボックスです。クリックによるオンオフで、きれいな円状に広がる(または、しぼむ)エフェクトを使い背景色の有無を切り替えます。

Toggle Me!

No! Toggle me instead!

Why not me?


htmlソース

<div class="container">
 <h3>Toggle Me!</h3>
 <div class="checkbox-container yellow">
  <input type="checkbox" checked id="toggle" />
  <label for="toggle"></label>
  <div class="active-circle"></div> 
 </div>
</div>
<div class="container">
 <h3>No! Toggle me instead!</h3>
 <div class="checkbox-container green">
  <input type="checkbox" checked id="toggle2" />
  <label for="toggle2"></label>
  <div class="active-circle"></div>
 </div>
</div>
<div class="container">
 <h3>Why not me?</h3>
 <div class="checkbox-container purple">
  <input type="checkbox" checked id="toggle3" />
  <label for="toggle3"></label>
  <div class="active-circle"></div>
 </div>
</div>


CSSソース

.container {
	background: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	overflow: hidden;
	width: 280px;
	height: 170px;
}
.container h3 {
	color: #111;
	font-size:18px;
	font-weight:400;
	margin: 0 0 25px;
	position: relative;
	z-index: 2;
}
.checkbox-container {
	display: inline-block;
	position: relative;
}
.checkbox-container label {
	background-color: #aaa;
	border: 1px solid #fff;
	border-radius: 20px;
	display: inline-block;
	position: relative;
	transition: all 0.3s ease-out;
	width: 45px;
	height: 25px;
	z-index: 2;
}
.checkbox-container label::after {
	content: ' ';
	background-color: #fff;
	border-radius: 50%;
	position: absolute;
	top: 1.5px;
	left: 1px;
	transform: translateX(0);
	transition: transform 0.3s linear;
	width: 20px;
	height: 20px;
	z-index: 3;
}
.checkbox-container input {
	visibility: hidden;
	position: absolute;
	z-index: 2;
}
.checkbox-container input:checked + label + .active-circle {
	transform: translate(-50%, -50%) scale(15);
}
.checkbox-container input:checked + label::after {
	transform: translateX(calc(100% + 0.5px));
}
.active-circle {
	border-radius: 50%;
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(calc(-50% - 10px), calc(-50% - 2px)) scale(0);
	transition: transform 0.6s ease-out;
	width: 30px;
	height: 30px;
	z-index: 1;
}
.checkbox-container.green .active-circle,
.checkbox-container.green input:checked + label {
	background-color: #47B881;
}
.checkbox-container.yellow .active-circle,
.checkbox-container.yellow input:checked + label {
	background-color: #F7D154;
}
.checkbox-container.purple .active-circle,
.checkbox-container.purple input:checked + label {
	background-color: #735DD0;
}

 

※参考にしたソース:https://codepen.io/FlorinPop17/pen/MxPXOL

 

 

 

戻るボタン

 

 

inserted by FC2 system