jquery - 根据内容溢出展开div或UL

标签 jquery html css xhtml

当里面有很多内容时,如何让div展开?

HTML:

<div class ="content">
    this is a test <br />
    this is a test <br />
    this is a test <br />
    this is a test <br />
    this is a test <br />
    this is a test <br />
    this is a test <br />
</div><br />
<div class="click-here">Click here to see more</div>

CSS:

div.content
{
    height:100px;
    width:300px;
    border:1px solid red;
    overflow:hidden;
}

div.click-here
{
    border:1px solid green;
    width:200px;
}

这是我的例子:http://jsfiddle.net/nvCvy/1/

Jquery 还是 CSS?

jquery scroll 会是更好的解决方案吗?或者您会使用 css 显示所有内容吗?

最佳答案

您需要进行以下两项更改。

  1. 不要提及高度,即删除 height 属性。

  2. 移除Overflow:hidden;

下面是工作demo .您可以根据需要添加任意数量的内容。

关于jquery - 根据内容溢出展开div或UL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10914796/

相关文章:

javascript - 上下文菜单的 jquery 停止事件

jquery - 如何根据是否选中来设置复选框标签内的 DIV 样式?

css - 三个页面使用一个母版页 CSS 问题

ios - 如何在 iOS Safari(在实际设备上)中将 "crop"关闭屏幕 <div>?

html - 如何在带有图像的圆圈之间放置线条?

jquery - 如何为 Bootstrap 中的多个选项卡制作轮播式导航栏?

javascript - 溢出-y 不适用于 fr

javascript - 隐藏第 1、3、4、6、7、9、10、12 个 div 容器

html - 我怎样才能使 <li> 展开以便它的 `padding-right` 生效?

javascript - CKEditor 按钮上没有空间