【发布时间】:2012-04-12 04:41:19
【问题描述】:
我在jsfiddle 有这个例子,手风琴只用 css3 制作,没有 js。
HTML:
<div class="ac-container">
<div>
<input id="ac-1" name="accordion-1" type="radio" checked />
<label for="ac-1">About us</label>
<article class="ac-small">
<p id="test_small">test</p> <-- this tag will come from php
</article>
</div>
<div>
<input id="ac-2" name="accordion-1" type="radio" />
<label for="ac-2">How we work</label>
<article class="ac-medium">
<p id="test_medium">test</p>
</article>
</div>
</div>
css:
.ac-container input:checked ~ article.ac-small{
height: 140px;
}
.ac-container input:checked ~ article.ac-medium{
height: 180px;
}
.ac-container input:checked ~ article.ac-large{
/* height: 240px;*/
}
我遇到的问题是高度已经设置好了,我用 php 添加内容,我不确定会有多少内容,所以我需要一个动态高度。
php 将加载 p 标签,因此我可以像这样找到高度:
var v = $("#test_small").height();
// add the height to the .ac-small
$('.ac-container input:checked article.ac-small').css("height", v+'px');
我遇到的问题是 css 不适用于选择器,我认为选择器 $('.ac-container input:checked article.ac-small') 是错误的。
【问题讨论】:
标签: jquery css height jquery-ui-accordion