Angular Material mat-nav-list 带居中图标的多行
Angular Material mat-nav-list multiline with centered icon
我正在努力尝试设置一个 mat-nav-list 和一些基于 mat-list-items 的两行。第一行应该是一个水平居中的图像,第二行是一个居中的标题文本。我都显示了,但是 img/icon 没有居中。 :/
这是一些代码:
<mat-nav-list class="list-container">
<a mat-list-item routerLink="/somewhere" routerLinkActive="active-link">
<span matLine class="icn_log"></span>
<span matLine>Centered Text</span>
</a>
</mat-nav-list>
我也使用了一些样式,更多的是用于去除填充和添加一些边框。但是我怎样才能给第一个带图标的跨度命令也使它居中呢?:
.list-container {
width: 100%;
padding-top: 1px;
border-right: 1px solid;
border-color: #ddd;
text-align: center;
}
.list-container .mat-list-item {
border: 1px solid;
border-right: 0px;
border-color: #ddd;
margin-top: -1px;
height: 80px;
}
.list-container .mat-list-item .mat-line {
padding-top: 5px;
padding-bottom: 5px;
}
.icn_log {
height: 32px;
width: 32px;
background-repeat: no-repeat;
background-image: url("assets/img/log.png");
background-position: 0;
}
尝试:
<mat-nav-list class="list-container">
<a mat-list-item routerLink="/somewhere" routerLinkActive="active-link">
<center>
<span matLine class="icn_log"></span>
<span matLine>Centered Text</span>
</center>
</a>
编辑 -
尝试将 0
的背景位置从 0
更改为 center
,对于 icn_log
,将 width
更改为 100%
.icn_log {
width: 100%;
background-position: center;
}
尝试像这样使用 mat-icon
指令:
<mat-list>
<a mat-list-item>
<mat-icon></mat-icon>
<span matLine>Centered Text</span>
</a>
</mat-list>
在 mat-icon
中,您可以使用 https://material.io/tools/icons. If you are new to material icons you can follow this guide: https://google.github.io/material-design-icons/。
暂时有一个解决方法,但它会被弃用,详情请见此处
https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep
:host ::ng-deep .mat-list-item-content {
flex-direction: column !important;
}
我正在努力尝试设置一个 mat-nav-list 和一些基于 mat-list-items 的两行。第一行应该是一个水平居中的图像,第二行是一个居中的标题文本。我都显示了,但是 img/icon 没有居中。 :/
这是一些代码:
<mat-nav-list class="list-container">
<a mat-list-item routerLink="/somewhere" routerLinkActive="active-link">
<span matLine class="icn_log"></span>
<span matLine>Centered Text</span>
</a>
</mat-nav-list>
我也使用了一些样式,更多的是用于去除填充和添加一些边框。但是我怎样才能给第一个带图标的跨度命令也使它居中呢?:
.list-container {
width: 100%;
padding-top: 1px;
border-right: 1px solid;
border-color: #ddd;
text-align: center;
}
.list-container .mat-list-item {
border: 1px solid;
border-right: 0px;
border-color: #ddd;
margin-top: -1px;
height: 80px;
}
.list-container .mat-list-item .mat-line {
padding-top: 5px;
padding-bottom: 5px;
}
.icn_log {
height: 32px;
width: 32px;
background-repeat: no-repeat;
background-image: url("assets/img/log.png");
background-position: 0;
}
尝试:
<mat-nav-list class="list-container">
<a mat-list-item routerLink="/somewhere" routerLinkActive="active-link">
<center>
<span matLine class="icn_log"></span>
<span matLine>Centered Text</span>
</center>
</a>
编辑 -
尝试将 0
的背景位置从 0
更改为 center
,对于 icn_log
,将 width
更改为 100%
.icn_log {
width: 100%;
background-position: center;
}
尝试像这样使用 mat-icon
指令:
<mat-list>
<a mat-list-item>
<mat-icon></mat-icon>
<span matLine>Centered Text</span>
</a>
</mat-list>
在 mat-icon
中,您可以使用 https://material.io/tools/icons. If you are new to material icons you can follow this guide: https://google.github.io/material-design-icons/。
暂时有一个解决方法,但它会被弃用,详情请见此处
https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep
:host ::ng-deep .mat-list-item-content {
flex-direction: column !important;
}