【发布时间】:2020-08-24 01:34:52
【问题描述】:
我正在尝试创建一个具有 20-60-20 弹性填充布局的页面,但中心的 div 应该占页面的 60%,它比它的内容更宽,所以它使它的内容看起来像偏心。
home.component.html:
<div fxLayout="row wrap" fxLayoutGap="20px grid">
<div *ngFor="let data of DUMMY_DATA">
<mat-card class="example-card" >
<img mat-card-image src="https://material.angular.io/assets/img/examples/shiba2.jpg" alt="Photo of a Shiba Inu">
<mat-card-content class="description-max-height">
<p>
{{data.description.length > 100 ? data.description.substring(0, 100) + '...' : data.description}}
</p>
</mat-card-content>
<mat-card-actions>
<button mat-button>LIKE</button>
<button mat-button>SHARE</button>
</mat-card-actions>
</mat-card>
</div>
</div>
home.component.css:
.example-card {
width: 250px;
height: 300px;
}
.description-max-height {
max-height: 30px;
}
app.component.html:
<mat-toolbar color="primary" style="margin-bottom: 20px">
<mat-toolbar-row>
<span>Some title</span>
<span class="toolbar-spacer"></span>
<button mat-button color="accent" (click)="openLoginDialog()">Log In</button>
<button mat-button color="accent" (click)="openSignupDialog()">Register</button>
</mat-toolbar-row>
</mat-toolbar>
<div fxLayout="row">
<div fxFlex="20"></div>
<router-outlet fxFlex="60"></router-outlet>
<div fxFlex="20"></div>
</div>
app.compoenent.css:
.toolbar-spacer {
flex: 1 1 auto;
}
我怎样才能实现这一点,以便在页面中心显示 home.component.html 而不会比它的内容更宽?
您可以找到 Stackblitz 示例 here
【问题讨论】:
-
你可以创建 stackblitz 示例吗?
-
@pc_coder 我添加了一个 Stackblitz 示例
-
我没有看到任何问题,它是 60% 你的下一个图像不适合所以下去然后你看到这个空区域吗?你想要什么结果?
标签: html css angular angular-flex-layout