gpt4 book ai didi

html - 容器宽度需要根据表格宽度动态变化

转载 作者:太空狗 更新时间:2023-10-29 13:47:02 25 4
gpt4 key购买 nike

我正在尝试为我的表实现一个容器,因此选择使用卡片类。如屏幕截图所示,容器扩展到屏幕的整个宽度。我希望容器宽度基于表格的宽度。在我的例子中,表格的宽度可以随着数据的呈现而改变水平地。我怎样才能使我的容器动态。如果超出屏幕大小,则应出现水平滚动条。正如您在下面的屏幕截图中看到的那样,它换行到下一行并且顶部右侧有间隙

截图

enter image description here

html

<style>
th,
td {
padding: 7px;
}

.scrollClass {
overflow-x: scroll;
}
.fundClassesTable {
margin: 0 auto;
font-size: 11px;
width: 100%;
}

.tableItem {
text-align: center;
border-left: solid 1px lightgrey;
border-top: solid 1px lightgrey;
border-right: solid 1px lightgrey;
border-bottom: solid 1px lightgrey;

}

.rowItem:hover {
background-color: #f5f7f7;
}



tr {
display: block;
float: left;
}

th,
td {
display: block;
min-height: 46px;
min-width: 300px;
}

label {
margin-left: 0.5rem;
vertical-align: middle
}


.panel-heading {
color: white;
background-color: #F59850;
border-color: #ddd;
overflow: hidden;
padding-top: 5px !important;
padding-bottom: 5px !important;
}

.panel-heading .left-label {
display: inline-block;
padding-top: 5px !important;

}

.panel-heading label {
margin-bottom: 0px !important;
}
</style>

<div>
<input type="checkbox" id="chk" style="width: 13px; height: 13px;" />
<label for="chk">Invested</label>

</div>

<div class="card scrollClass">
<div class="card-header panel-heading">
<span class="left-label" style="font-size: 18px; font-weight: bold; ">Fund Classes</span>
<div class="pull-right" style="padding-right:10px; display: inline-block; vertical-align:middle">
<!-- <label style="text-align: center; vertical-align:middle" class="btn btn-default pull-right"> <i
data-bind="visible: true" class="fa fa-plus-square"></i><input type="checkbox" class="hidden" /> Add
Class</label> -->
<button style="text-align: center; vertical-align:middle" class="btn btn-default pull-right" (click)="openFundClassModal()"> <i
data-bind="visible: true" class="fa fa-plus-square"></i> Add Class</button>
</div>
</div>

<div *ngIf="FundClasses && FundClasses.FundDetailsViewModel">

<table class="fundClassesTable table-striped">

<tr>
<th class="tableItem bold">Fund Name</th>
<th class="tableItem bold">Accounting Class Name</th>
<th class="tableItem bold">Class ID</th>
<th class="tableItem bold">Legal Fund Class</th>
<th class="tableItem bold">Inception Date</th>
<th class="tableItem bold">Invested Amount</th>
<th class="tableItem bold">Vehicle Type</th>
<th class="tableItem bold">Closure Status</th>
<th class="tableItem bold">Is Side Pocket?</th>
<th class="tableItem bold">Is Thematic?</th>
<th class="tableItem bold">Cogency Class?</th>
<th class="tableItem"></th>
</tr>

<ng-container *ngFor="let fundClass of FundClasses.FundDetailsViewModel">
<tr *ngFor="let f of fundClass['FundClassDetailsViewModel'] | keyvalue">
<td class="tableItem">{{ f.value.FundName}}</td>
<td class="tableItem">{{ f.value.Description}}</td>
<td class="tableItem">{{f.value.Id}}</td>
<td *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-dropdownlist style="width:100%" [(ngModel)]="f.value.LegalFundClassId"
class="form-control form-control-sm" [data]="fundClass.PrimaryLegalFundClasses"
[filterable]="false" textField="Description" [valuePrimitive]="true" valueField="Id">
</kendo-dropdownlist>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.LegalFundClassName}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-datepicker style="width:100%" [format]="'MMMM yyyy'" [topView]="'decade'"
[bottomView]="'year'" [(ngModel)]="f.value.InceptionDate"
class="form-control form-control-sm">
</kendo-datepicker>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.InceptionDate | date:"'MMMM yyyy"}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem" style="width:100%">
<input kendoTextBox [(ngModel)]="f.value.InvestedAmount"
style="width: 284px; height: 29.5px;" />
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.InvestedAmount | number : '.2-2'}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-dropdownlist style="width:100%" [(ngModel)]="f.value.VehicleTypeId"
class="form-control form-control-sm" [data]="FundClasses.VehicleTypes" [filterable]="false"
textField="Name" [valuePrimitive]="true" valueField="Id"></kendo-dropdownlist>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.VehicleTypeName}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-dropdownlist style="width:100%" [(ngModel)]="f.value.ClosureStatusId"
class="form-control form-control-sm" [data]="FundClasses.ClosureStatuses"
[filterable]="false" textField="Name" [valuePrimitive]="true" valueField="Id">
</kendo-dropdownlist>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.ClosureStatusName}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<input type="checkbox" value="{{f.value.IsSidePocket}}" id="chk"
style="width: 13px; height: 13px;" />
<label for="chk">Yes</label>

</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.IsSidePocket == true ? 'Yes' : 'No'}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<input type="checkbox" value="{{f.value.IsThematic}}" style="width: 13px; height: 13px;" />
<label for="chk">Yes</label>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.IsThematic == true ? 'Yes' : 'No'}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-dropdownlist style="width:100%" [(ngModel)]="f.value.CogencyClassId"
class="form-control form-control-sm" [data]="fundClass.CogencyClasses" [filterable]="false"
textField="Name" [valuePrimitive]="true" valueField="Id"></kendo-dropdownlist>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.CogencyClassId}}
</td>
<td class="tableItem">

<button *ngIf="!EditMode[f.value.Id]" type="button" class="btn btn-primary btn mr-1 col-sm-4"
(click)="buttonClicked(f.value.Id)">Edit</button>
<button *ngIf="EditMode[f.value.Id]" type="button" class="btn btn-primary btn mr-1 col-sm-3"
(click)="Update(f.value.Id)">Save</button>
<button *ngIf="EditMode[f.value.Id]" type="button" class="btn btn-primary btn mr-1 col-sm-3"
(click)="buttonClicked(f.value.Id)">Delete</button>
<button *ngIf="EditMode[f.value.Id]" type="button" class="btn btn-primary btn mr-1 col-sm-3"
(click)="buttonClicked(f.value.Id)">Cancel</button>

</td>
</tr>
</ng-container>
</table>
</div>
</div>


<shared-modal [modalSize]="1" class="survey-edit" [open]="fundClassWindowOpened">
<div style="width: 100%;" header>
<h4 class="modal-title">
<div style="text-align: right"><button aria-label="Dismiss" class="close"
style="margin-top: -48px" type="button" (click)="dismissFundClassModal()">X</button>
</div>
</h4>
</div>
<div body>
<mgr-addFundClass></mgr-addFundClass>

</div>
<div footer>
</div>
</shared-modal>

基于 Aarons 评论的应用解决方案

enter image description here

最佳答案

所以根据评论,我想我现在理解你了。首先,让我们删除使用 float: left 将容器排成一行的非常过时的方法:

tr {
display: block;
float: left; //<== Remove this line
min-width: 300px; //<== Optional: Just to make sure your table columns don't get too small if they have less content.
}

让我们使用更现代的东西,比如 flexbox。所以将 display: flex; 添加到您的 tbody
问题是您仍然有一个空白空间。要填写它,请使用 flex-grow在每个 tr 上。最后归结为:

.fundClassesTable tbody {
display: flex;
}

.fundClassesTable tbody tr {
flex-grow: 1;
}

.scrollClass {
overflow-x: scroll;
display: grid; //<== Add this line.
}

这是您的示例(或 http://jsfiddle.net/h5oc70va/1/,如果您愿意):

.fundClassesTable tbody {
display: flex;
}

th,
td {
padding: 7px;
}

.scrollClass {
overflow-x: scroll;
display: grid;
}

.fundClassesTable {
margin: 0 auto;
font-size: 11px;
width: 100%;
}

.tableItem {
text-align: center;
border-left: solid 1px lightgrey;
border-top: solid 1px lightgrey;
border-right: solid 1px lightgrey;
border-bottom: solid 1px lightgrey;
}

.rowItem:hover {
background-color: #f5f7f7;
}

tr {
display: block;
flex-grow: 1;
}

th,
td {
display: block;
min-height: 46px;
min-width: 300px;
}

label {
margin-left: 0.5rem;
vertical-align: middle
}

.panel-heading {
color: white;
background-color: #F59850;
border-color: #ddd;
overflow: hidden;
padding-top: 5px !important;
padding-bottom: 5px !important;
}

.panel-heading .left-label {
display: inline-block;
padding-top: 5px !important;
}

.panel-heading label {
margin-bottom: 0px !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet" />

<div>
<input type="checkbox" id="chk" style="width: 13px; height: 13px;" />
<label for="chk">Invested</label>

</div>

<div class="card scrollClass">
<div class="card-header panel-heading">
<span class="left-label" style="font-size: 18px; font-weight: bold; ">Fund Classes</span>
<div class="pull-right" style="padding-right:10px; display: inline-block; vertical-align:middle">
<!-- <label style="text-align: center; vertical-align:middle" class="btn btn-default pull-right"> <i
data-bind="visible: true" class="fa fa-plus-square"></i><input type="checkbox" class="hidden" /> Add
Class</label> -->
<button style="text-align: center; vertical-align:middle" class="btn btn-default pull-right" (click)="openFundClassModal()"> <i
data-bind="visible: true" class="fa fa-plus-square"></i> Add Class</button>
</div>
</div>

<div *ngIf="FundClasses && FundClasses.FundDetailsViewModel">

<table class="fundClassesTable table-striped">

<tr>
<th class="tableItem bold">Fund Name</th>
<th class="tableItem bold">Accounting Class Name</th>
<th class="tableItem bold">Class ID</th>
<th class="tableItem bold">Legal Fund Class</th>
<th class="tableItem bold">Inception Date</th>
<th class="tableItem bold">Invested Amount</th>
<th class="tableItem bold">Vehicle Type</th>
<th class="tableItem bold">Closure Status</th>
<th class="tableItem bold">Is Side Pocket?</th>
<th class="tableItem bold">Is Thematic?</th>
<th class="tableItem bold">Cogency Class?</th>
<th class="tableItem"></th>
</tr>

<ng-container *ngFor="let fundClass of FundClasses.FundDetailsViewModel">
<tr *ngFor="let f of fundClass['FundClassDetailsViewModel'] | keyvalue">
<td class="tableItem">{{ f.value.FundName}}</td>
<td class="tableItem">{{ f.value.Description}}</td>
<td class="tableItem">{{f.value.Id}}</td>
<td *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-dropdownlist style="width:100%" [(ngModel)]="f.value.LegalFundClassId" class="form-control form-control-sm" [data]="fundClass.PrimaryLegalFundClasses" [filterable]="false" textField="Description" [valuePrimitive]="true" valueField="Id">
</kendo-dropdownlist>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.LegalFundClassName}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-datepicker style="width:100%" [format]="'MMMM yyyy'" [topView]="'decade'" [bottomView]="'year'" [(ngModel)]="f.value.InceptionDate" class="form-control form-control-sm">
</kendo-datepicker>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.InceptionDate | date:"'MMMM yyyy"}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem" style="width:100%">
<input kendoTextBox [(ngModel)]="f.value.InvestedAmount" style="width: 284px; height: 29.5px;" />
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.InvestedAmount | number : '.2-2'}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-dropdownlist style="width:100%" [(ngModel)]="f.value.VehicleTypeId" class="form-control form-control-sm" [data]="FundClasses.VehicleTypes" [filterable]="false" textField="Name" [valuePrimitive]="true" valueField="Id"></kendo-dropdownlist>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.VehicleTypeName}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-dropdownlist style="width:100%" [(ngModel)]="f.value.ClosureStatusId" class="form-control form-control-sm" [data]="FundClasses.ClosureStatuses" [filterable]="false" textField="Name" [valuePrimitive]="true" valueField="Id">
</kendo-dropdownlist>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.ClosureStatusName}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<input type="checkbox" value="{{f.value.IsSidePocket}}" id="chk" style="width: 13px; height: 13px;" />
<label for="chk">Yes</label>

</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.IsSidePocket == true ? 'Yes' : 'No'}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<input type="checkbox" value="{{f.value.IsThematic}}" style="width: 13px; height: 13px;" />
<label for="chk">Yes</label>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.IsThematic == true ? 'Yes' : 'No'}}
</td>
<td [attr.id]="'f.value.Id'" *ngIf="EditMode[f.value.Id]" class="tableItem">
<kendo-dropdownlist style="width:100%" [(ngModel)]="f.value.CogencyClassId" class="form-control form-control-sm" [data]="fundClass.CogencyClasses" [filterable]="false" textField="Name" [valuePrimitive]="true" valueField="Id"></kendo-dropdownlist>
</td>
<td [attr.id]="'f.value.Id'" *ngIf="!EditMode[f.value.Id]" class="tableItem" style="width:100%">
{{ f.value.CogencyClassId}}
</td>
<td class="tableItem">

<button *ngIf="!EditMode[f.value.Id]" type="button" class="btn btn-primary btn mr-1 col-sm-4" (click)="buttonClicked(f.value.Id)">Edit</button>
<button *ngIf="EditMode[f.value.Id]" type="button" class="btn btn-primary btn mr-1 col-sm-3" (click)="Update(f.value.Id)">Save</button>
<button *ngIf="EditMode[f.value.Id]" type="button" class="btn btn-primary btn mr-1 col-sm-3" (click)="buttonClicked(f.value.Id)">Delete</button>
<button *ngIf="EditMode[f.value.Id]" type="button" class="btn btn-primary btn mr-1 col-sm-3" (click)="buttonClicked(f.value.Id)">Cancel</button>

</td>
</tr>
</ng-container>
</table>
</div>
</div>


<shared-modal [modalSize]="1" class="survey-edit" [open]="fundClassWindowOpened">
<div style="width: 100%;" header>
<h4 class="modal-title">
<div style="text-align: right"><button aria-label="Dismiss" class="close" style="margin-top: -48px" type="button" (click)="dismissFundClassModal()">X</button>
</div>
</h4>
</div>
<div body>
<mgr-addFundClass></mgr-addFundClass>

</div>
<div footer>
</div>
</shared-modal>

如果您需要任何解释,请告诉我,但我相信代码应该是不言自明的。

关于html - 容器宽度需要根据表格宽度动态变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55922665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com