html - 如何自动调整列和行的大小

标签 html css

我发现了很多关于自动调整行和列大小的文章,例如下面的 CSS 代码:

   textarea[readonly="readonly"], textarea[readonly] { background-color:white; }
    float colWidth = [[[tableView tableColumns] objectAtIndex:1]width];
    NSString *content = [[[tempArray objectAtIndex:row] objectForKey:@"tValue"] string];
    float textWidth = [content sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Lucida Grande" size:15],NSFontAttributeName ,nil]].width;
    float newHeight = ceil(textWidth/colWidth);
    newHeight = (newHeight * 17) + 13;
            if(newHeight < 47){
                return 47;
            }   
            return newHeight;
            table {
      width: 700px;
    }

table tr td {
  width: 350px;
  height: auto;
}

但是我的代码似乎没有任何效果

这是我的表格代码,我希望它根据将从数据库中获取的数据自动调整大小:

$myRes = "<form action='' method='post'>
          <fieldset style='width: 10px'>
          <legend align='left'><strong>Results</strong></legend>
          <p>
          <table width='auto' border='1' cellspacing='1' cellpadding='1' align='center'>
          <tr>
          <th align='center' scope='row'>A</th>
          <td><textarea class=readonly name=testA id=testA cols=65 rows=3>" . $result['testA'] . "</textarea></td>
          </tr>
          <tr>
          <th scope='row'>B</th>
          <td><textarea class=readonly name=testB id=testB cols=65 rows=3>" . $result['testB'] . "</textarea></td>
          </tr>
          </table>
          </p>
          </fieldset>
          </form>";

最佳答案

尝试以下操作:

$("textarea").height( $("textarea")[0].scrollHeight );

window.setTimeout( function() {
    $("textarea").height( $("textarea")[0].scrollHeight );
}, 1);​

关于html - 如何自动调整列和行的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20325991/

相关文章:

php - 删除 Woocommerce 中的“添加到购物车”通知并更改 "add to cart"按钮

css - Foundation 导航栏中的垂直对齐文本

jquery - 将样式应用于跨度和表格不起作用

javascript - 选择 Ajax 回调

Javascript 发送对象作为参数

css - 第一次动画迭代后位置不同 'from'

html - 如何解决 safari 中手写 html dingbat 字体大小问题

javascript - 将表单数据发送到 HTML 页面并使用 Javascript 检索它而无需任何 PHP/Python

javascript - 基于正则表达式匹配启用 javascript/jquery 中的按钮

html - 为父级设置溢出时如何避免在行中间切割文本?