Да, можно создать чистый CSS раскрывающийся список, используя хак с флажком .
В этом примере я отделил <label>
от <input>
и связал их:
- , давая
<input>
id
- , давая
<label>
соответствующий for
атрибут
Рабочий пример (Версия 1):
Эта версия скользит вниз.
.open-content {
display: none;
}
.label-text {
position: relative;
display: block;
z-index: 12;
height: 32px;
line-height: 32px;
padding: 6px;
color: #EC008C;
font-size: 20px;
font-weight: 700;
background-color: rgb(255, 255, 255);
cursor: pointer;
}
.label-text::after {
content: '+';
display: inline;
color: rgb(0, 0, 0);
font-size: 32px;
font-weight: 700;
vertical-align: bottom;
}
.content {
position: relative;
display: inline-block;
z-index: 6;
padding: 6px;
background-color: #F5F5F5;
opacity: 0;
transform: translateY(-50px);
transition: all 0.6s linear;
}
.open-content:checked ~ .content {
opacity: 1;
transform: translateY(0);
}
<input id="open-content" class="open-content" type="checkbox">
<label class="label-text" for="open-content">
Open this tab
</label>
<div class="content">
<p>Show this content with slidedown</p>
</div>
Рабочий пример (версия 2):
Эта версия разворачивается.
.open-content {
display: none;
}
.label-text {
position: relative;
display: block;
z-index: 12;
height: 32px;
line-height: 32px;
padding: 6px;
color: #EC008C;
font-size: 20px;
font-weight: 700;
background-color: rgb(255, 255, 255);
cursor: pointer;
}
.label-text::after {
content: '+';
display: inline;
color: rgb(0, 0, 0);
font-size: 32px;
font-weight: 700;
vertical-align: bottom;
}
.content {
position: relative;
display: inline-block;
z-index: 6;
padding: 6px;
height: 0;
background-color: #F5F5F5;
opacity: 0;
overflow: hidden;
transition: all 0.6s linear;
}
.open-content:checked ~ .content {
opacity: 1;
height: 120px;
}
<input id="open-content" class="open-content" type="checkbox">
<label class="label-text" for="open-content">
Open this tab
</label>
<div class="content">
<p>Show this content with slidedown</p>
<p>Show this content with slidedown</p>
<p>Show this content with slidedown</p>
</div>
Дополнительная литература: