Jquery 切换位置绝对底部
我有一个绝对
定位的容器,它是底部
对齐的。
现在我想切换
(显示/隐藏)一些内容,而容器不会大于其内容 - 并且最好不要显式设置高度。
html
<div id="outer">
<div class="expandableContent">
<p class="toggler">Toggle</p>
<div>
<p>Some content here</p>
<p>Some content there</p>
<p>Some content everywhere</p>
</div>
</div>
</div>
css
#outer {
height: 300px;
position: relative;
}
.expandableContent {
position: absolute;
bottom: 10px;
}
.expandableContent > div {
display: none;
}
jquery
$(document).ready(function () {
$('.toggler').click( function() {
$(this).next().toggle(1000);
});
});
I've got an absolute
positioned container, which is bottom
aligned.
Now I would like to toggle
(show/hide) some content without the container getting larger than its contents - and preferably without setting the height explicitly.
html
<div id="outer">
<div class="expandableContent">
<p class="toggler">Toggle</p>
<div>
<p>Some content here</p>
<p>Some content there</p>
<p>Some content everywhere</p>
</div>
</div>
</div>
css
#outer {
height: 300px;
position: relative;
}
.expandableContent {
position: absolute;
bottom: 10px;
}
.expandableContent > div {
display: none;
}
jquery
$(document).ready(function () {
$('.toggler').click( function() {
$(this).next().toggle(1000);
});
});
Here's a link: http://jsfiddle.net/SunnyRed/A8pNv/1/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不需要设置高度...只需设置可扩展 div 的宽度。我已经在你的 jsfiddle 中为你修改了这个。
我唯一做的就是:
You don't need to set the height...just the width of the explandable div. I have modified this for you in your jsfiddle.
The only thing i did was:
将上面的内容添加到包含文本的 div 中。
xGreen 正确地设置了宽度,但某些浏览器还要求禁用文本换行。以 Chrome 为例,仅设置宽度是不够的。
Add the above the the div containing the text.
xGreen is correct that setting the width will work, but some browsers with also require text-wrapping to be disabled. An example would be with Chrome, just setting the width is not enough.
看看这个,现在优雅多了。
工作演示
Take a look at this, is much elegant now.
Working demo