在jQuery UI对话框中的Textarea高度/宽度

kra*_*626 3 html css jquery textarea jquery-ui

我弹出一个jQuery对话框,允许用户发送确认电子邮件.我有一些文字,然后是文字区域.对话框是可扩展的,我希望文本区域填满对话框的整个区域,除了顶部需要的50px高度以显示文本.

正确地将textarea高度设置为100%允许textarea随着对话框大小的变化而扩展/收缩.但是,它没有为文本顶部留出空间.

我如何让textarea填充对话框的整个区域(高度和宽度)除了我的文本所在的前50px高度.

谢谢.

HTML:

<div id="dialog-message-email" title="Send Email">

    <p style="height:50px">
        <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
        Confirmation Email to be sent to user.
    </p>
    <div>
    <textarea id="ConfirmEmailText" class="ui-corner-all ui-widget-content" style="height:100%;padding:5px; font-family:Sans-serif; font-size:1.2em;"></textarea>
    </div>

    </div>
Run Code Online (Sandbox Code Playgroud)

kap*_*apa 5

您可以使用绝对定位.

更新:当给定绝对定位时,textarea不会延伸到其父级,因此我设置了textarea周围的div,而textarea只会调整自己的div维度.

这里工作的例子.我玩底部和右边调整textarea的边框和填充,而不是最好的,可能会调整,但它的工作原理.

所以使它工作的基本东西是这样的:

#dialog-message-email {
    position: relative;
    min-height: 200px; /* the child is absolute, so we need a minimum height */
}

#dialog-message-email div { /* this one will stretch */
      position: absolute;
      top: 50px;
      bottom: 0;
      left: 0;
      right: 0;
}

#ConfirmEmailText { /* and the textarea follows its parent's dimensions */
      width: 100%;
      height: 100%;
}
Run Code Online (Sandbox Code Playgroud)

更新2:我偶然发现了一篇与之相关的伟大文章,并通过将包装器伪装成textarea本身来扩展它:

div {
  position: absolute;
  left: 5px; 
  top: 5px;
  right: 5px; 
  bottom: 5px;
  border: 1px solid #CCC; /* style like textarea */
}

textarea {
  width: 100%;
  height: 100%;
  margin: 0; /* don't want to add to container size */
  border: 0; /* don't want to add to container size */
}
Run Code Online (Sandbox Code Playgroud)