以下示例中有两个表。没有为列设置宽度。我不希望两个表中的列的固定宽度。我想根据生成的动态文本使列宽相同。我正在使用angularjs和html。这是plunkr - https://plnkr.co/edit/AhS2AmL5O6QxZaHNAzPp?p=preview
HTML -
<html>
<head>
<script src="angular.min.js"></script>
<script src="script.js"></script>
<link rel="stylesheet" href="style.css"/>
<link rel="stylesheet" href="font-awesome.min.css"/>
<link rel="stylesheet" href="bootstrap.min.css" />
</head>
<body data-ng-app="testApp" data-ng-controller="treeTable">
<hr>
<button type="button" class="btn btn-success" data-dismiss="modal" data-ng-click="save()">SaveFilter</button>
<div class="row">
<div class="col-md-9">
<div class="tableheight">
<table class="table-nested childtable">
<thead>
<tr>
<!-- <th >
<input data-ng-checked="(list | selected).length == list.length" data-ng-click="toggleAllCheckboxes($event)" type="checkbox" />
</th> -->
<th >
<input data-ng-checked="(list | selected).length == list.length" data-ng-click="toggleAllCheckboxes($event)" type="checkbox" /> Name
</th>
<th class="cell-members">
Version
</th>
<th class="cell-members">
Size
</th>
<th class="cell-members">
Modified By
</th>
<th class="cell-members">
Labels
</th>
<th class="cell-members">
Description
</th>
</tr>
</thead>
<tbody class="newRepo" style="font-size:12px" data-ng-class="{opened: item.opened}" data-ng-include="'table_tree.html'" data-ng-repeat="item in list"></tbody>
</table>
</div>
<script id="table_tree.html" type="text/ng-template">
<tr ng-class="{parent: item.children}" ng-init="parentScope = $parent.$parent; initCheckbox(item, parentScope.item)">
<td class="cell-name top-border" ng-if="level && level > 1">
<span style="padding-left: 30px" > <input ng-change="toggleCheckbox(item, parentScope)" ng-model="item.selected" type="checkbox" />
{{item.name}} </span>
</td>
<td class="cell-name top-border" ng-if=" (!level && level <= 1 ) || (level && level <= 1)">
<span style="padding-left:11px" ng-click="item.opened = !item.opened"></span> <input ng-change="toggleCheckbox(item, parentScope)" ng-model="item.selected" type="checkbox" />
{{item.name}}
</td>
<td class="cell-name top-border" ng-if="!level">
<span class="indent" ng-click="item.opened = !item.opened"></span> <input ng-change="toggleCheckbox(item, parentScope)" ng-model="item.selected" type="checkbox" />
{{item.name}}
</td>
<td class="cell-members">
{{item.Version}}
</td>
<td class="cell-members">
{{item.Size}}
</td>
<td class="cell-members">
{{item.ModifiedBy}}
</td>
<td class="cell-members">
{{item.Labels}}
</td>
<td class="cell-members">
{{item.Description}}
</td>
</tr>
<tr class="children" ng-if="item.children && item.children.length > 0">
<td colspan="6">
<table class="childtable">
<tbody style="font-size:12px" ng-class="{opened: item.opened}" ng-include="'table_tree.html'" ng-init="level = level + 1" ng-repeat="item in item.children"></tbody>
</table>
</td>
</tr>
</script>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
我认为这就是你想要的,将宽度改为最大宽度:
.table-nested .cell-name {
max-width: 15rem;
/*width: 60%;*/
}
不要忘记评论宽度。
请参阅plnkr:https://plnkr.co/edit/gYWusE9tqMX6D76bhcmW?p=preview
您也可以使用60%。所以:max-width: 60%
答案 1 :(得分:0)
如果您希望所有列的宽度相同,并且由于您确定每个表中只有五列,我建议:
<table style="table-layout:fixed">
<col style="width:20%" span="5" />
<tr><!--stuffs...--></tr>
</table>