自动高度计算div [英] Auto height calculation of div

查看:368
本文介绍了自动高度计算div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算 content div height,并将其应用于 wrapper div。



我有脚本,但这里的问题是,我有自动增长 text-area code> content div动态增加 text-area 内容



如何自动将已生成的div高度应用于 wrapper div。我想要 wrapper div也与 content div一起成长。

 < div class =wrapper> 
< div class =content>
< p> lorem ipsum elit sitrialm ipsum elit sitrialm ipsum elit sitlorem ipsum elit sifgfgfgfgfgfgfgfgfgfgtlorem ipsum elit sitransm ipsum elit dfdfdfdfdfdfdsitlorer ipsum elit sititre ipsum elit sititre ipsum elit sitlore
< textarea>< / textarea>
< / p>
< / div>
< / div>

DEMO



PS:我无法更改 / code

请在resize函数中添加以下行:

  var contentHeight = box.parents(。content)height ; 
$(。wrapper)。css({min-height:contentHeight + 40});


I need to calculate the content div height and apply it to the wrapper div.

I have script which does that but the problem here is, I have auto grow text-area inside the content div which increases the text-area and content height dynamically while typing inside.

How do I automatically apply the grown div height to the wrapper div. I want wrapper div also to grow along with content div.

<div class="wrapper">
   <div class="content">
     <p>lorem ipsum elit sitlorem ipsum elit sitlorem ipsum elit sitlorem ipsum elit sifgfgfgfgfgfgfgfgfgtlorem ipsum elit sitlorem ipsum elit dfdfdfdfdfdfdsitlorem ipsum elit sitlorem ipsum elit sitlorem ipsum elit sitlore
       <textarea></textarea>
     </p>
   </div>
  </div>

DEMO

P.S: I can not change the position:absolute of the .Content div

解决方案

Please add below lines in resize function

    var contentHeight = box.parents(".content").height();
    $(".wrapper").css({"min-height":contentHeight+40});

这篇关于自动高度计算div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆