Pra*_*eep 6 angular-material angular angular5 angular6 angular7
我试图在每行创建 6 个图块,每个图块由左上角的金额、右上角的 + 符号、慈善机构名称下方、最左边的日期下方等组成。但一切都在中间发生。如何自定义每个 mat-grid-tile 的样式。
HTML Example
mat-grid-list cols="6" rowHeight="4:3" [gutterSize]="'10px'">
<mat-grid-tile *ngFor="let item of items; let i=index">
<div class="div-table">
<div class="div-row">
<div class="div-cell" style="font-weight: bold; font-size: medium;">{{amount | currency}}</div>
</div>
<div class="div-row">
<div>{{item.Name}}</div>
</div>
</div>
</mat-grid-tile>
CSS Example
mat-grid-tile {
background: lightblue;
}
.div-table {
display: table;
width: auto;
background-color: #eee;
}
.div-row {
display: table-row;
width: auto;
clear: both;
}
.div-cell {
float: left;
display: table-column;
width: 200px;
background-color: #ccc;
}
Run Code Online (Sandbox Code Playgroud)
这里有一个Stackblitz 演示。
您可以将 a 放在div图块内部作为容器元素(以避免搞乱mat-grid-tile样式)。在这个容器内,您可以flex-box根据需要构建布局。每个图块的容器div可能具有以下内容:
.container {
display: flex;
flex-direction: column;
justify-content: space-between;
width: 100%;
height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
然后,在容器内div,您可以有 3 个section元素:页眉(占用 20% 以上的可用垂直空间)、页脚(占用 20% 以上的可用垂直空间)和正文(占用页眉未占用的任何空间)和页脚):
.container > .header {
flex-basis: 20%;
order: 1; /* Assure this is the first element, at the top */
}
.container > .footer {
flex-basis: 20%;
order: 3; /* Assure this is the third element, at the bottom */
}
.container > .body {
flex: 1;
order: 2; /* Assure this is the second element, in the middle */
}
Run Code Online (Sandbox Code Playgroud)
您几乎可以从这里做任何您想做的事情。例如,您说您希望在标题中将名称放在左侧,将符号放在右侧。因此,让我们将标头也变成另一个 Flex 容器本身,其中包含两个section元素:header-start和header-end(以防万一您想要不同的 CSS 样式):
.header {
display: flex;
justify-content: space-between;
flex-basis: 20%;
order: 1;
}
Run Code Online (Sandbox Code Playgroud)
整体 html 会是这样的:
<mat-grid-list cols="2" rowHeight="2:1">
<mat-grid-tile *ngFor="let i of [1,2,3,4]">
<div class="container">
<section class="header">
<section class="header-start>
Charity name
</section>
<section class="header-end">
<mat-icon>home</mat-icon>
</section>
</section>
<section class="footer">
footer
</section>
<section class="body">
body
</section>
</div>
</mat-grid-tile>
</mat-grid-list>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6028 次 |
| 最近记录: |