所以我有一个非常简单的手风琴只使用CSS,我想改变文字点击查看详细信息,然后再次点击再次回来,任何人都知道我会怎么做?如果不使用JS会很棒,但我会采取任何一种方式!谢谢!
<input type="checkbox" id="checkbox-1" name="checkbox-accordion" /><label for="checkbox" style="text-align:right;">Click for details</label>
.accordion {
font-size:14px;
border:none;
border-radius:10px;
width:790px;
padding:10px;
margin: 0 0 0 10px;
-moz-border-radius: 0 0 15px 15px;
border-radius: 0 0 15px 15px;
-webkit-box-shadow: 2px 2px 6px 0px rgba(148,148,148,1);
-moz-box-shadow: 2px 2px 6px 0px rgba(148,148,148,1);
box-shadow: 2px 2px 6px 0px rgba(148,148,148,1);
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
}
.accordion ul {
list-style:none;
margin:0;
padding:0;
}
.accordion li {
margin:0;
padding:0;
}
.accordion [type=radio], .accordion [type=checkbox] {
display:none;
}
.accordion label {
display:block;
font-size:16px;
line-height:16px;
background:#ffffff;
border:none;
color:#464646;
text-shadow:1px 1px 1px rgba(255,255,255,0.3);
font-weight:700;
cursor:pointer;
-webkit-transition: all .2s ease-out;
-moz-transition: all .2s ease-out;
}
.accordion ul li label:hover, .accordion [type=radio]:checked ~ label, .accordion [type=checkbox]:checked ~ label {
}
.accordion .content {
padding:0 10px;
overflow:hidden;
-webkit-transition: all .5s ease-out;
-moz-transition: all .5s ease-out;
}
.accordion p {
color:#333;
margin:0 0 10px;
}
/* Vertical */
.vertical ul li {
overflow:hidden;
margin:0 0 1px;
}
.vertical ul li label {
padding:10px;
}
.vertical [type=radio]:checked ~ label, .vertical [type=checkbox]:checked ~ label {
border-bottom:0;
}
.vertical ul li .content {
height:0px;
border-top:0;
}
.vertical [type=radio]:checked ~ label ~ .content, .vertical [type=checkbox]:checked ~ label ~ .content {
height:220px;
}
答案 0 :(得分:3)
你可以使用:after伪元素和内容,如下所示:
input#checkbox-1:checked + label {
visibility: hidden;
position: relative;
}
input#checkbox-1:checked + label:after {
visibility: visible;
position: absolute;
left: 0;
top: 0;
content: "Close";
}
虽然没有额外的标记,但这不适用于IE。您需要在标签内放置一个元素并使用CSS
隐藏它<input type="checkbox" id="checkbox-2" name="checkbox-accordion" />
<label for="checkbox" style="text-align:right;"><span>Click for details</span></label>
input#checkbox-2:checked + label span {
display: none;
}
input#checkbox-2:checked + label:after {
content: "Close";
}
答案 1 :(得分:0)
只需在标签内使用几个跨度,并根据是否选中该复选框显示它们
#checkbox-1:checked + label > .on{
display: inline;
}
#checkbox-1:checked + label > .off,
#checkbox-1 + label > .on {
display: none;
}
<input type="checkbox" id="checkbox-1" name="checkbox-accordion" />
<label for="checkbox" style="text-align:right;"><span class="on">I'm ON</span><span class="off">I'm OFF</span></label>