|

Click events

ラベル要素とインプット要素を使用してクリックイベントにより表示を切り替える機能を実装します。

ご自由にご利用ください。

Previews

Examples html

<!-- container -->

<div class="container">

	<input type="checkbox" id="target" />

	<div class="content">

		<label for="target"></label>

	</div>

</div>

<!-- /container -->

Examples css

/* - container - */

.container {
	width: 100%;
	height: auto;
	margin: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	background-color: rgba(0, 0, 0, 0.0);
}

.container input[type="checkbox"] {
	display: none;
}

.container .content {
	width: 100%;
	height: 25vh;
	margin: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	background-color: rgba(0, 0, 0, 0.0);
	border: 1px solid rgba(0, 0, 0, 1.0);
}

.container .content label {
	width: 100%;
	height: 100%;
	margin: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	background-color: rgba(0, 0, 0, 0.0);
	cursor: pointer;
}

.container .content label::after {
	width: 100%;
	height: 100%;
	margin: 0px 0px 0px 0px;
	padding: 25px 25px 25px 25px;
	display: -webkit-flex;
	display: flex;
	-webkit-flex-direction: column;
	flex-direction: column;
	-webkit-flex-wrap: wrap;
	flex-wrap: wrap;
	-webkit-justify-content: center;
	justify-content: center;
	-webkit-align-content: flex-start;
	align-content: flex-start;
	-webkit-align-items: flex-start;
	align-items: flex-start;
}

.container input[type="checkbox"] + .content label::after {
	content: "クリックしてください。(before clicking.)";
	background-color: rgba(0, 0, 0, 1.0);
	font-family: sans-serif;
	font-size: 1.4rem;
	font-style: normal;
	font-weight: 200;
	text-decoration: none;
	color: rgba(255, 255, 255, 1.0);
}

.container input[type="checkbox"]:checked + .content label::after {
	content: "クリックしてください。(after clicking.)";
	background-color: rgba(255, 255, 255, 1.0);
	font-family: sans-serif;
	font-size: 1.4rem;
	font-style: normal;
	font-weight: 200;
	text-decoration: none;
	color: rgba(0, 0, 0, 1.0);
}

/* - /container - */

Summary

最後までご高覧いただきましてありがとうございました。

ラベル要素とインプット要素を使用してクリックイベントにより表示を切り替える機能をご紹介させていただきました。

必要に応じて各コードを変更してご自由にご利用ください。

現場からは以上でした。