0

I wonder how to center vertically and horizontally the content of a card text (or card block).

enter image description here

Here's the code I'am using

<div class="clr-row">
  <div class="clr-col-2">
    <div class="card">
      <div class="card-header">This month credits used</div>
      <div class="card-block">
        <div class="card-text" *ngIf="credits.length > 0">
          <h1>{{creditsCurrent | number : '1.2-2'}}</h1>
        </div>
      </div>
    </div>
  </div>
</div>

I would like the "70.10" string to be aligned vertically and horizontally

Thank you for your help

Fred Mériot
  • 4,157
  • 9
  • 33
  • 50

1 Answers1

0

Using an h1 here for styling purposes is not advised as you'll get issues with accessibility understanding the DOM structure of the page.

You'll want to put the text straight into the div.card-text element. Then create a set of styles that reflects the styling you want for the text, and in this case I've setup a new class so I can easily reuse this elsewhere.

<div class="clr-row">
  <div class="clr-col-2">
    <div class="card">
      <div class="card-header">This month credits used</div>
      <div class="card-block">
        <div class="card-text numeric-card-text" *ngIf="credits.length > 0">
          {{creditsCurrent | number : '1.2-2'}}
        </div>
      </div>
    </div>
  </div>
</div>
.numeric-card-text {
  text-align: center;
  font-size: 2rem;
  padding: 1rem;
  font-weight: 400;
}
Jeremy Wilken
  • 6,965
  • 22
  • 21
  • Yes, the

    is a bad idea. Your CSS works : the text is centered horizontally. Do you know how to center it vertically. Thank you

    – Fred Mériot Nov 07 '19 at 09:04
  • Use CSS to manage the layout, here is another description https://stackoverflow.com/questions/8865458/how-do-i-vertically-center-text-with-css – Jeremy Wilken Nov 08 '19 at 21:46