|

Tabs css

ラベル要素とインプット要素を使用してコンテンツ領域を切り替えるタブ機能を実装します。

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

Previews

This is the first tab. Tabs are useful for showing or hiding large amounts of content.
This is the second tab. Tabs are useful for showing or hiding large amounts of content.
This is the third tab. Tabs are useful for showing or hiding large amounts of content.

Examples html

<!-- tab -->

<div class="tab">

	<input type="radio" id="tab1" name="tab" checked="checked" />
	<input type="radio" id="tab2" name="tab" />
	<input type="radio" id="tab3" name="tab" />

	<div class="label">

		<label for="tab1" class="label1">Section 1</label>
		<label for="tab2" class="label2">Section 2</label>
		<label for="tab3" class="label3">Section 3</label>

	</div>

	<div class="container">

		<div class="content content1">
			<div class="description">This is the first tab. Tabs are useful for showing or hiding large amounts of content.</div>
		</div>

		<div class="content content2">
			<div class="description">This is the second tab. Tabs are useful for showing or hiding large amounts of content.</div>
		</div>

		<div class="content content3">
			<div class="description">This is the third tab. Tabs are useful for showing or hiding large amounts of content.</div>
		</div>

	</div>

</div>

<!-- /tab -->

Examples css

/* - tab - */

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

input[type="radio"] {
	display: none;
}

.label {
	width: 100%;
	height: auto;
	margin: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	background-color: rgba(0, 0, 0, 0.0);
	display: -webkit-flex;
	display: flex;
	-webkit-flex-direction: row;
	flex-direction: row;
	-webkit-flex-wrap: wrap;
	flex-wrap: wrap;
	-webkit-justify-content: flex-start;
	justify-content: flex-start;
	-webkit-align-content: flex-start;
	align-content: flex-start;
	-webkit-align-items: flex-start;
	align-items: flex-start;
}

label.label1,
label.label2,
label.label3 {
	width: -webkit-calc( ( 100% + 2px ) / 3 );
	width: calc( ( 100% + 2px ) / 3 );
	min-height: 50px;
	margin: 0px -1px 0px 0px;
	padding: 10px 10px 10px 10px;
	background-color: rgba(0, 0, 0, 0.8);
	border: 1px solid rgba(0, 0, 0, 0.8);
	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;
	cursor: pointer;
	transition: all .5s;
}

label.label1,
label.label2,
label.label3 {
	font-family: sans-serif;
	font-size: 1.4rem;
	font-style: normal;
	font-weight: 200;
	text-decoration: none;
	color: rgba(255, 255, 255, 1.0);
}

label.label1:hover,
label.label2:hover,
label.label3:hover {
	color: rgba(255, 255, 255, 0.5);
}

label.label1:active,
label.label2:active,
label.label3:active {
	color: rgba(255, 255, 255, 1.0);
}

#tab1:checked ~ label.label1,
#tab2:checked ~ label.label2,
#tab3:checked ~ label.label3 {
	width: 100%;
	height: auto;
	margin: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
}

#tab1:checked ~ .label label.label1,
#tab2:checked ~ .label label.label2,
#tab3:checked ~ .label label.label3 {
	background-color: rgba(255, 255, 255, 1.0);
	border-bottom: 0px solid rgba(0, 0, 0, 0.0);
	color: rgba(0, 0, 0, 1.0);
	cursor: auto;
}

.container {
	width: 100%;
	height: auto;
	margin: -1px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	background-color: rgba(255, 255, 255, 1.0);
	border: 1px solid rgba(0, 0, 0, 0.8);
}

.content {
	display: none;
}

#tab1:checked ~ .container .content1,
#tab2:checked ~ .container .content2,
#tab3:checked ~ .container .content3 {
	display: block;
}

.description {
	width: 100%;
	min-height: 100px;
	margin: 1px 0px 0px 0px;
	padding: 10px 10px 10px 10px;
	background-color: rgba(0, 0, 0, 0.0);
	animation: opacity .5s;
}

.description {
	font-family: sans-serif;
	font-size: 1.4rem;
	font-style: normal;
	font-weight: 200;
	text-decoration: none;
	color: rgba(0, 0, 0, 1.0);
}

@keyframes opacity {
	0% {
		opacity: 0;
	}
	100% {
		opacity: 1;
	}
}

/* - /tab - */

Summary

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

ラベル要素とインプット要素を使用してコンテンツ領域を切り替えるタブ機能をご紹介させていただきました。

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

現場からは以上でした。