|
Sunday, July 7th, 2024
Accordions css closed type
ラベル要素とインプット要素を使用してコンテンツ領域を開閉するアコーディオン機能を実装します。
ご自由にご利用ください。
Previews
Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.
Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.
Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.
Examples html
<!-- accordion -->
<div class="accordion">
<article>
<input type="checkbox" id="check1" name="accordion" class="check" />
<label for="check1" class="label1">Section 1</label>
<section class="content1">
<div class="description">Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.</div>
</section>
</article>
<article>
<input type="checkbox" id="check2" name="accordion" class="check" />
<label for="check2" class="label2">Section 2</label>
<section class="content2">
<div class="description">Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.</div>
</section>
</article>
<article>
<input type="checkbox" id="check3" name="accordion" class="check" />
<label for="check3" class="label3">Section 3</label>
<section class="content3">
<div class="description">Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.</div>
</section>
</article>
</div>
<!-- /accordion -->
Examples css
/* - accordion - */
.accordion {
width: 100%;
height: auto;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background-color: rgba(0, 0, 0, 0.0);
}
article {
width: 100%;
height: auto;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background-color: rgba(0, 0, 0, 0.0);
}
input[type="checkbox"].check {
display: none;
}
label.label1,
label.label2,
label.label3 {
width: 100%;
min-height: 50px;
margin: 0px 0px 0px 0px;
padding: 10px 10px 10px 10px;
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: space-between;
justify-content: space-between;
-webkit-align-content: center;
align-content: center;
-webkit-align-items: center;
align-items: center;
cursor: pointer;
}
label.label1 {
border: 1px solid rgba(0, 0, 0, 1.0);
}
label.label2 {
margin: -1px 0px 0px 0px;
border: 1px solid rgba(0, 0, 0, 1.0);
}
label.label3 {
margin: -1px 0px 0px 0px;
border: 1px solid rgba(0, 0, 0, 1.0);
}
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(0, 0, 0, 1.0);
}
label.label1::after,
label.label2::after,
label.label3::after {
content: "+";
}
label.label1::after,
label.label2::after,
label.label3::after {
font-family: sans-serif;
font-size: 1.4rem;
font-style: normal;
font-weight: 200;
text-decoration: none;
color: rgba(0, 0, 0, 1.0);
}
input[type="checkbox"].check:checked + label.label1::after,
input[type="checkbox"].check:checked + label.label2::after,
input[type="checkbox"].check:checked + label.label3::after {
content: "-";
}
input[type="checkbox"].check:checked + label.label1::after,
input[type="checkbox"].check:checked + label.label2::after,
input[type="checkbox"].check:checked + label.label3::after {
font-family: sans-serif;
font-size: 1.4rem;
font-style: normal;
font-weight: 200;
text-decoration: none;
color: rgba(0, 0, 0, 1.0);
}
input[type="checkbox"].check:checked + label.label1 + section.content1,
input[type="checkbox"].check:checked + label.label2 + section.content2,
input[type="checkbox"].check:checked + label.label3 + section.content3 {
width: 100%;
height: 100px;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background-color: rgba(0, 0, 0, 0.0);
}
input[type="checkbox"].check:checked + label.label3 + section.content3 {
margin: -1px 0px 0px 0px;
}
section.content1,
section.content2,
section.content3 {
overflow: hidden;
width: 100%;
height: 0px;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background-color: rgba(0, 0, 0, 0.0);
transition: height .3s;
}
section.content1 {
border-right: 1px solid rgba(0, 0, 0, 1.0);
border-left: 1px solid rgba(0, 0, 0, 1.0);
}
section.content2 {
border-right: 1px solid rgba(0, 0, 0, 1.0);
border-left: 1px solid rgba(0, 0, 0, 1.0);
}
section.content3 {
margin: -1px 0px 0px 0px;
border-right: 1px solid rgba(0, 0, 0, 1.0);
border-bottom: 1px solid rgba(0, 0, 0, 1.0);
border-left: 1px solid rgba(0, 0, 0, 1.0);
}
.description,
.description,
.description {
width: 100%;
height: auto;
margin: 0px 0px 0px 0px;
padding: 10px 10px 10px 10px;
background-color: rgba(0, 0, 0, 0.0);
}
.description,
.description,
.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);
}
/* - /accordion - */
Summary
最後までご高覧いただきましてありがとうございました。
ラベル要素とインプット要素を使用してコンテンツ領域を開閉するアコーディオン機能をご紹介させていただきました。
必要に応じて各コードを変更してご自由にご利用ください。
現場からは以上でした。