jquery - 使用 jQuery 根据 div 中的内容调整最小高度

标签 jquery html css

我是 jquery 的新手,我想知道如何为 jquery 添加一种方法,以根据其中的内容量调整 div 的最小高度。我总是希望最小高度大概在 700 左右,但随着用户在某些页面上添加更多内容,它需要拉伸(stretch)以适合该内容。

我如何整合它?请具体说明 css、html 等,因为我是 jquery 的新手。

最佳答案

太简单了:

HTML

<div class="foo" >
This is sample<br />
This is sample<br />
This is sample<br />
This is sample<br />
This is sample<br />
This is sample<br />
This is sample<br />
</div>​

JQuery

$(function() {
    $(".foo").css("min-height", function() {
        return $(this).height();
    });
});

关于jquery - 使用 jQuery 根据 div 中的内容调整最小高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13687021/

相关文章:

css - 谷歌浏览器的样式滚动条

html - 为什么蓝色框上方有一个空格?

javascript - 使用jquery模拟拖放

javascript - 此 jQuery 代码无法正常工作的新手问题

jquery - 使用 jQuery width() 和 height() 方法

c# - 我如何 [简单地] 在业务线 Web 应用程序中使用 JSON 数据

asp.net - 带有 IE8 问题的 ASP gridview 中的按钮

html - 获取整个 html 文件并提取一个 JSON 段落

javascript - 我无法在我的 js 文件中放置两个或更多 svg 形状并让它们显示在我的网站上

javascript - div 容器上的负 z-index 阻止访问处理程序。我该如何解决这个问题?