【问题标题】:How to align text/ content in angular and css?如何在角度和 css 中对齐文本/内容?
【发布时间】:2021-03-30 21:49:18
【问题描述】:

我正在尝试使用 angular 对齐下方展开/折叠问题栏中的文本。下面的代码是 HTML/Angular sn-ps 之一。有不少这样的代码块构成了下图

  <mat-expansion-panel hideToggle>
  <mat-expansion-panel-header>
   <mat-panel-title>
    User Data Management
   </mat-panel-title>
  <mat-panel-description>
   What is an agent?
  </mat-panel-description>
  </mat-expansion-panel-header>
  <p>An agent is an individual hired to liaise with a user via the robot</p>
  </mat-expansion-panel>

CSS

 styles: [

  mat-panel-description {
  color: red;
  align-content: center;
 }

如您所见,即使我已将内容对齐到中心,红色文本也完全不对齐。

有什么建议吗?

【问题讨论】:

    标签: html css angular


    【解决方案1】:

    我会这样做:

    mat-expansion-panel-header {
        display: flex;
        flex-flow: row;
        width: 100%;
        justify-content: space-between;
    }
    mat-panel-description {
        width: 300px; // im using fixed width so that it will be aligned, maybe there's an other way though
        text-align: center;
    }
    

    不确定这是否可行,但值得一试。

    【讨论】:

      【解决方案2】:

      align-content:center; 更改为justify-content:center;。就这些。

      更新:mat-panel-title 大小适合内容,所以你需要修复它的宽度:

      mat-panel-title {
          width: 50%; //change based on your requirements
      }
      

      【讨论】:

      • 似乎不起作用。它似乎把一些物品推到了左边。我也试过 align-text 也不起作用
      • 还是什么都没有。您的更新只是将描述推到更接近标题的位置?
      • 我刚刚在stackbllitz中测试过,看看:stackblitz.com/edit/…
      猜你喜欢
      • 1970-01-01
      • 2020-02-08
      • 1970-01-01
      • 2017-03-17
      • 2021-10-05
      • 2020-07-13
      • 2020-07-26
      • 2014-06-07
      • 2015-07-03
      相关资源
      最近更新 更多