我在下面有一个纯CSS手风琴列表的代码。我想知道是否有可能将标题下的文本放在像这里的示例中那样:http://codepen.io/pirrera/pen/KwzMGZ,但仅使用纯CSS?任何事都有帮助,欢呼。
.wrapper {
max-width: 960px;
margin: 0 auto;
}
/* Acordeon styles */
.tab {
position: relative;
margin-bottom: 1px;
width: 100%;
color: #005bab;
overflow: hidden;
}
.input {
position: absolute;
opacity: 0;
z-index: -1;
}
.label {
position: relative;
text-align:center;
display: block;
padding: 0 0 0 1em;
background: #e2ecf6;
font-size:14px;
font-family:Verdana;
font-weight: bold;
line-height: 6;
cursor: pointer;
}
.tab-content {
max-height: 0;
overflow: hidden;
background: #f4f8fc;
-webkit-transition: max-height .5s;
-o-transition: max-height .5s;
transition: max-height .5s;
}
.tab-content p {
margin: 1em;
}
/* :checked */
.input:checked ~ .tab-content {
max-height: 10em;
}
/* Icon */
.label::after {
position: absolute;
left: 0;
top: 0;
display: block;
width: 3em;
height: 3em;
line-height: 3;
text-align: center;
-webkit-transition: all .35s;
-o-transition: all .35s;
transition: all .35s;
}
.input[type=checkbox] + .label::after {
content: "+";
}
.input[type=radio] + .label::after {
content: "";
}
.input[type=checkbox]:checked + .label::after {
transform: rotate(315deg);
}
.input[type=radio]:checked + .label::after {
transform: rotateX(180deg);
}
.bottombar{
content: "";
display:block;
height:1em;
width:100%;
background-color:#00688B;
}
<div class="wrapper">
<div class="tab">
<input name="tabs" class="input" id="tab-one" type="checkbox"/>
<label class="label" for="tab-one">Label One</label>
<div class="tab-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</div>
<div class="tab">
<input name="tabs" class="input" id="tab-two" type="checkbox"/>
<label class="label" for="tab-two">Label Two</label>
<div class="tab-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</div>
<div class="tab">
<input name="tabs" class="input" id="tab-three" type="checkbox"/>
<label class="label" for="tab-three">Label Three</label>
<div class="tab-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</div>
<div class="bottombar"></div>
</div>
答案 0 :(得分:1)
是的,您可以使用transform: scale()
缩小内容并使用opacity: 0
隐藏内容,然后在标签/输入为:checked
时将其转换为正常值
.wrapper {
max-width: 960px;
margin: 0 auto;
}
/* Acordeon styles */
.tab {
position: relative;
margin-bottom: 1px;
width: 100%;
color: #005bab;
overflow: hidden;
}
.input {
position: absolute;
opacity: 0;
z-index: -1;
}
.label {
position: relative;
text-align: center;
display: block;
padding: 0 0 0 1em;
background: #e2ecf6;
font-size: 14px;
font-family: Verdana;
font-weight: bold;
line-height: 6;
cursor: pointer;
}
.tab-content {
max-height: 0;
overflow: hidden;
background: white;
}
.tab-content p {
padding: 1em;
margin: 0 0 0 2em;
background: #f4f8fc;
}
/* :checked */
.input:checked ~ .tab-content {
max-height: 10em;
}
/* Icon */
.label::after {
position: absolute;
left: 0;
top: 0;
display: block;
width: 3em;
height: 3em;
line-height: 3;
text-align: center;
-webkit-transition: all .35s;
transition: all .35s;
}
.input[type=checkbox] + .label::after {
content: "+";
}
.input[type=radio] + .label::after {
content: "";
}
.input[type=checkbox]:checked + .label::after {
-webkit-transform: rotate(315deg);
transform: rotate(315deg);
}
.input[type=radio]:checked + .label::after {
-webkit-transform: rotateX(180deg);
transform: rotateX(180deg);
}
.bottombar {
content: "";
display: block;
height: 1em;
width: 100%;
background-color: #00688B;
}
.tab-content {
transform: scale(0.5);
opacity: 0;
transition: transform .5s, opacity .5s, -webkit-transform .5s, max-height .5s;
}
input:checked ~ .tab-content {
-webkit-transform: scale(1);
transform: scale(1);
opacity: 1;
}
&#13;
<div class="wrapper">
<div class="tab">
<input name="tabs" class="input" id="tab-one" type="checkbox"/>
<label class="label" for="tab-one">Label One</label>
<div class="tab-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</div>
<div class="tab">
<input name="tabs" class="input" id="tab-two" type="checkbox"/>
<label class="label" for="tab-two">Label Two</label>
<div class="tab-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</div>
<div class="tab">
<input name="tabs" class="input" id="tab-three" type="checkbox"/>
<label class="label" for="tab-three">Label Three</label>
<div class="tab-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</div>
<div class="bottombar"></div>
</div>
&#13;
答案 1 :(得分:1)
选中复选框后,您可以为段落的比例设置动画
.input:checked~.tab-content p {
transform: scale(1);
}
请参阅以下代码:
.wrapper {
max-width: 960px;
margin: 0 auto;
}
/* Acordeon styles */
.tab {
position: relative;
margin-bottom: 1px;
width: 100%;
color: #005bab;
overflow: hidden;
}
.input {
position: absolute;
opacity: 0;
z-index: -1;
}
.label {
position: relative;
text-align: center;
display: block;
padding: 0 0 0 1em;
background: #e2ecf6;
font-size: 14px;
font-family: Verdana;
font-weight: bold;
line-height: 6;
cursor: pointer;
}
.tab-content {
max-height: 0;
overflow: hidden;
padding: 0px;
-webkit-transition: max-height .5s;
-o-transition: max-height .5s;
transition: max-height .5s;
padding-left: 20px;
background: #c3d7ea;
}
.tab-content .container {
padding: 1em;
margin: 0;
transform: scale(0.6);
-webkit-transition: transform .5s;
-o-transition: transform .5s;
transition: transform .5s;
background: #f4f8fc;
}
/* :checked */
.input:checked~.tab-content {
max-height: 10em;
}
.input:checked~.tab-content .container {
transform: scale(1);
}
/* Icon */
.label::after {
position: absolute;
left: 0;
top: 0;
display: block;
width: 3em;
height: 3em;
line-height: 3;
text-align: center;
-webkit-transition: all .35s;
-o-transition: all .35s;
transition: all .35s;
}
.input[type=checkbox]+.label::after {
content: "+";
}
.input[type=radio]+.label::after {
content: "";
}
.input[type=checkbox]:checked+.label::after {
transform: rotate(315deg);
}
.input[type=radio]:checked+.label::after {
transform: rotateX(180deg);
}
.bottombar {
content: "";
display: block;
height: 1em;
width: 100%;
background-color: #00688B;
}
<div class="wrapper">
<div class="tab">
<input name="tabs" class="input" id="tab-one" type="checkbox" />
<label class="label" for="tab-one">Label One</label>
<div class="tab-content">
<div class="container">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
<div>this is another div</div>
</div>
</div>
</div>
<div class="tab">
<input name="tabs" class="input" id="tab-two" type="checkbox" />
<label class="label" for="tab-two">Label Two</label>
<div class="tab-content">
<div class="container">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</div>
</div>
<div class="tab">
<input name="tabs" class="input" id="tab-three" type="checkbox" />
<label class="label" for="tab-three">Label Three</label>
<div class="tab-content">
<div class="container">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</div>
</div>
<div class="bottombar"></div>
</div>
答案 2 :(得分:0)
使用transform: scale()
来&#34;成长&#34; /&#34;缩小&#34;内容和效果的过渡。
笔:https://codepen.io/kjkta/pen/MmLewZ
我已添加:
.tab-content {
transition: .5s transform;
transform: scale(.1);
}
.input:checked ~ .tab-content {
transform: scale(1);
}
答案 3 :(得分:0)
<强> EDITED 强>
这是一个简单而实用的示例:但是,您无法使用css模拟“onclick”事件。您还可以查看此帖子以获得更多说明:Can I have an onclick effect in CSS?
如果您不介意在代码中使用一些纯JavaScript,请参阅此示例:
https://jsfiddle.net/8xs83phb/
如果您想要一个基于“悬停”事件的手风琴,请参阅以下代码。
ul {
margin: 0;
padding: 0;
}
ul li {
list-style-type: none;
}
h2 {
margin: 0;
text-align: center;
font: normal 22px Arial, Verdana;
}
.box {
width: 200px;
max-height: 40px;
padding: 10px 0;
background: #fdfdfd;
box-sizing: border-box;
overflow: hidden;
cursor: pointer;
border-bottom: 1px solid black;
transition: all 0.5s;
}
.box:hover {
max-height: 300px;
}
<ul>
<li>
<div class='box'>
<h2>Item One</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</li>
<li>
<div class='box'>
<h2>Item Two</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</li>
<li>
<div class='box'>
<h2>Item Three</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p>
</div>
</li>
</ul>