【发布时间】:2018-11-08 11:08:10
【问题描述】:
我想将图像和按钮内容与垫卡的中心对齐。
已尝试使用以下 CSS 样式: 证明内容:中心 左边距:自动,右边距:自动 左边距:50% ,右边距:50% 内容对齐:居中 等等
此时我尝试了 Andrew Lobban 提供的所有解决方案。我非常感谢他耐心地与我一起寻找解决方案。
卡片组件如下:
HTML
<div>
<mat-grid-list cols="6" rowHeight="250px">
<mat-grid-tile *ngFor="let card of card" [colspan]="card.cols" [rowspan]="card.rows">
<mat-card class="dashboard-card">
<mat-card-header>
</mat-card-header>
<div>
<mat-card-content class="dashboard-card-content">
<img src={{card.IMGPath}}>
<a mat-raised-button color="primary" href={{card.ButtonLink}}>{{card.ButtonLabel}}</a>
</mat-card-content>
</div>
</mat-card>
</mat-grid-tile>
</mat-grid-list>
</div>
CSS
.grid-container {
margin: 20px;
}
.dashboard-card {
position: absolute;
top: 15px;
left: 15px;
right: 15px;
bottom: 15px;
max-width: 150px;
min-width: 150px;
}
.dashboard-card-content {
justify-content: center
}
打字稿
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-property-management',
templateUrl: './property-management.component.html',
styleUrls: ['./property-management.component.css']
})
export class PropertyManagementComponent {
card = [{
title: 'Capital Control', cols: 1, rows: 1,
IMGPath: 'redacted' ,
ButtonLabel:'Capital Control',
ButtonLink:'redacted'
},
{
title: 'New Entity', cols: 1, rows: 1,
IMGPath: 'redacted' ,
ButtonLabel:'New Entity',
ButtonLink:'redacted'
},
];
}
这些卡片在这里被使用: HTML
<div class="grid-container">
<h3 class="mat-h3">Property Management</h3>
<mat-divider></mat-divider>
<app-property-management></app-property-management>
<h3 class="mat-h3">Information Technology</h3>
<mat-divider></mat-divider>
<app-information-technology></app-information-technology>
</div>
使用此代码,它们呈现如下:Current Image
感谢大家的时间和耐心。
【问题讨论】: