[英]right text align mat-expansion-panel material component
I want to align the description text of mat-expansion-panel
component to the right我想将
mat-expansion-panel
组件的描述文本向右对齐
I have tried using align-text to right but nothing is changing Here's my HTML我曾尝试使用 align-text to right 但没有任何改变 这是我的 HTML
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
Cycle ingénieur en informatique
</mat-panel-title>
<mat-panel-description>
2014-2017
</mat-panel-description>
</mat-expansion-panel-header>
....
</mat-expansion-panel>
CSS : CSS :
mat-panel-description {
text-align: right;
}
Here's the actual behavior这是实际行为
I would have that 2014-2017 stay stuck to the right.我会让 2014-2017 保持在右边。
The panel header content are contained in a span which is a flexbox so you can use that to push the contents out to the sides.面板标题内容包含在一个 flexbox 跨度中,因此您可以使用它来将内容推送到两侧。
view:观点:
<mat-expansion-panel>
<mat-expansion-panel-header class="right-aligned-header">
<mat-panel-title>
Cycle ingénieur en informatique
</mat-panel-title>
<mat-panel-description>
2014-2017
</mat-panel-description>
</mat-expansion-panel-header>
css (this has to be global css eg. styles.css not in the component style): css(这必须是全局 css,例如,styles.css 不在组件样式中):
.right-aligned-header > .mat-content {
justify-content: space-between;
}
.mat-content > mat-panel-title, .mat-content > mat-panel-description {
flex: 0 0 auto;
}
Here is a Stack Blitz demo这是一个Stack Blitz 演示
Based on this solution: https://github.com/angular/components/issues/10024基于此解决方案: https : //github.com/angular/components/issues/10024
.mat-expansion-panel-header-description, .mat-expansion-panel-header-title {
flex-basis: 0;
}
and reading again the problem, this worked for me:并再次阅读问题,这对我有用:
.mat-expansion-panel-header-description {
display: flex;
justify-content: flex-end;
}
The easiest solution I found is to reset flex-grow
of mat-panel-description
:我找到的最简单的解决方案是重置
mat-panel-description
flex-grow
:
// my.component.css
mat-panel-description.right-aligned {
flex-grow: 0;
}
// my.component.html
...
<mat-expansion-panel-header>
<mat-panel-description class="right-aligned">
2014-2017
</mat-panel-description>
</mat-expansion-panel-header>
...
Add fxLayoutAlign="end" to mat-panel-description.将 fxLayoutAlign="end" 添加到 mat-panel-description。 It worked for me.
它对我有用。
'<mat-panel-description fxLayoutAlign="end">
2014-2017
</mat-panel-description>'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.