【发布时间】:2013-02-12 07:21:06
【问题描述】:
我有一个纯 CSS 可折叠 div,它基于使用 :target psuedoclass 的其他人的代码。我要设置的是一个包含 12 个以上问题的页面,当您单击 + 按钮时,答案 div 会在下方展开。如果不编写大量额外的 CSS,我无法弄清楚如何在此页面上制作多个折叠 div 元素。有人对如何编写此代码有建议,以便最小化我的 CSS 代码吗? (即,因此我不必为 12 多个问题中的每一个都输入一堆唯一的选择器)。
我不能使用 Javascript,因为这是在不允许 JS 的 wordpress.com 网站上进行的。
这是我的小提琴:http://jsfiddle.net/dmarvs/94ukA/4/
<div class="FAQ">
<a href="#hide1" class="hide" id="hide1">+</a>
<a href="#show1" class="show" id="show1">-</a>
<div class="question"> Question Question Question Question Question Question Question Question Question Question Question? </div>
<div class="list">
<p>Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer </p>
</div>
</div>
/* source: http://www.ehow.com/how_12214447_make-collapsing-lists-java.html */
.FAQ {
vertical-align: top;
height:auto !important;
}
.list {
display:none;
height:auto;
margin:0;
float: left;
}
.show {
display: none;
}
.hide:target + .show {
display: inline;
}
.hide:target {
display: none;
}
.hide:target ~ .list {
display:inline;
}
/*style the (+) and (-) */
.hide, .show {
width: 30px;
height: 30px;
border-radius: 30px;
font-size: 20px;
color: #fff;
text-shadow: 0 1px 0 #666;
text-align: center;
text-decoration: none;
box-shadow: 1px 1px 2px #000;
background: #cccbbb;
opacity: .95;
margin-right: 0;
float: left;
margin-bottom: 25px;
}
.hide:hover, .show:hover {
color: #eee;
text-shadow: 0 0 1px #666;
text-decoration: none;
box-shadow: 0 0 4px #222 inset;
opacity: 1;
margin-bottom: 25px;
}
.list p{
height:auto;
margin:0;
}
.question {
float: left;
height: auto;
width: 90%;
line-height: 20px;
padding-left: 20px;
margin-bottom: 25px;
font-style: italic;
}
【问题讨论】:
-
对于没有使用 wordpress 的任何人,我可以说请不要这样做。它是一种 hack,它破坏了非常烦人的页面的背面功能。
标签: css collapsable