css - 使此表列宽度适合。不太宽也不太窄

标签 css angularjs html ngtable

我正在使用 angularjs ngtable 模块来创建这个表。

这里是相关的html代码;

<div ng-controller="TestCtrl" class="container">
    <table ng-table="tableParams" class="table table-bordered">
        <thead>
        <tr>
            <th>name</th>
            <th>remarks</th>
        </tr>
        </thead>

        <tbody>
        <tr ng-repeat="test in $data">
            <td data-title="'name'" >
                {{test.name}}
            </td>
            <td data-title="'remarks'">
                {{test.remarks}}
            </td>
        </tr>
        </tbody>
    </table>
</div>

name 字符串恰好很短。有时,它最多为 5 个字符。有时,最多 3 个字符。 name 的列宽通常比需要的宽。如何使这个列恰到好处?

最佳答案

你可以用css来做。在您的表中添加一个额外的类,例如表格扩展

所以你的 table 会是

<table ng-table="tableParams" class="table table-bordered table-expand">

和这个类的CSS

.table-expand tbody tr td:nth-child(1n) {
    white-space:nowrap;
}

.table-expand tbody tr td:nth-child(2n) {
    width:100%
}

看这个demo

关于css - 使此表列宽度适合。不太宽也不太窄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34174132/

相关文章:

css - Internet Explorer 透明度

html - 无法让搜索框在 Bootstrap 导航栏中居中

html - 使 anchor 填充父宽度和高度的 100%

javascript - 我如何告诉 Grunt 不要在构建任务中缩小或连接 js 文件?

javascript - accordion+tab = 之前的内容不消失

jquery - 使 div 和子 div 至少延伸到浏览器窗口的整个高度

angularjs - 如何将数据从模型返回到 Controller

javascript - 如何使用 angular.js 实时检查输入字段是否与另一个变量匹配

javascript - JS触发checkbox的checked attr不会动态改变

video - html5 : display video inside canvas