右文本对齐垫 - 扩展 - 面板材料组件

时间:2018-03-19 23:30:32

标签: html css angular angular-material

我想将mat-expansion-panel组件的说明文字与右侧

对齐

我尝试过使用对齐文本,但没有任何改变 这是我的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:

mat-panel-description {
    text-align: right;
}

这是实际行为

example

我希望2014年能够坚持到右边。

4 个答案:

答案 0 :(得分:8)

面板标题内容包含在作为flexbox的范围中,因此您可以使用它将内容推送到两侧。

视图:

<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(这必须是全局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;
}

这是Stack Blitz demo

答案 1 :(得分:4)

我找到的最简单的解决方案是将flex-grow的{​​{1}}重置:

mat-panel-description
// my.component.css

mat-panel-description.right-aligned {
  flex-grow: 0;
}

StackBlitz

答案 2 :(得分:0)

将fxLayoutAlign =“ end”添加到mat-panel-description。它对我有用。

'<mat-panel-description fxLayoutAlign="end">
2014-2017
</mat-panel-description>'

答案 3 :(得分:-1)

基于以下解决方案:https://github.com/angular/components/issues/10024

.mat-expansion-panel-header-description, .mat-expansion-panel-header-title {
  flex-basis: 0;
}

再读一次问题,这对我有用:

.mat-expansion-panel-header-description {
  display: flex;
  justify-content: flex-end;
}
相关问题