简体   繁体   English

如何在角4中对齐左右文本mat-card-header?

[英]How to align left and right text mat-card-header in angular 4?

I need to align the text content in the header on left and right side of header tag. 我需要在标题标记左侧和右侧的标题中对齐文本内容。 i tried different ideas, but none works for me. 我尝试了不同的想法,但没有一个适合我。 help me. 帮我。

 <div style="width: 40%">
  <mat-card>
    <mat-card-header class="card-container">
      <mat-card-title class="card-container-right"> Test right</mat-card-title>
      <mat-card-title class="card-container-left"> Test left</mat-card-title>
    </mat-card-header>
    <mat-card-content>
    </mat-card-content>
  </mat-card>
</div>

You can also do this if you want to continue to use the mat-title elements: 如果要继续使用mat-title元素,也可以执行此操作:

See working StackBlitz Example 请参阅StackBlitz示例

In your (I'll call it) example-card.component.html file 在你的(我称之为)example-card.component.html文件中

<mat-card  >
<mat-card-header>
 <mat-card-title class="card-container-left"> Test left</mat-card-title>
 <mat-card-title class="card-container-right"> Test right</mat-card- title>
</mat-card-header>
<mat-card-content>
</mat-card-content>

Then in your example-card.component.css 然后在你的example-card.component.css中

.card-container-right{
  display: inline;
  float: right;
}

.card-container-left{
  display: inline;
}

..and finally in your styles.css ..最后在你的styles.css中

.mat-card-header-text{
  width: 100% !important;
}

The trick to this is overriding Angular materials .mat-card-header-text to be 100% the width of the mat-card-header . 这方面的技巧是覆盖Angular材料.mat-card-header-textmat-card-header的宽度的100%。 Otherwise it behaves like in inline element and only takes up the width of its children elements text. 否则它的行为类似于内联元素,只占用其子元素文本的宽度。 Preventing you from spacing them out. 防止你将它们隔开。

You can use what material design uses in mat-toolbar 您可以使用材质设计在mat-toolbar中使用的内容

<mat-card-title>
   <span>Test left</span>
   <span class="fill-remaining-space"></span>
   <span>Test right</span>
</mat-card-title> 

in your .css 在你的.css中

.fill-remaining-space {
   flex: 1 1 auto;
}

I am sorry, This doesn't work !!!!! 对不起,这不行!!!!! Works in Mat-Toolbar, bat not in Mat-card Title. 在Mat-Toolbar中工作,不在Mat-card Title中。

Here is how it works, I knew I had used it somewhere 这是它的工作原理,我知道我曾在某个地方使用它

<mat-card>
  <mat-card-title-group>
    <span>Test left</span>
    <span class="fill-remaining-space"></span>
    <span>Test right</span>
  </mat-card-title-group>
</mat-card>

see : https://stackblitz.com/edit/angular-rb5vmu for working example 请参阅: https//stackblitz.com/edit/angular-rb5vmu以获取工作示例

add custom css on .mat-card-header class .mat-card-header类上添加自定义css

 .mat-card-header{
        justify-content: flex-end /* for right*/
        justify-content: flex-start /* for left*/
        justify-content: centre /* for center*/

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM