Search code examples
htmlcssionic-frameworkionic3

How to add circle with number on ion card header


I was trying to make some card with numbering(circle with number inside), but something seems wrong. I can't make it circle and center

Here's what I want but when I try to make it, it become like this

Here is some of my code,

<ion-card-header style="padding:0px;border-bottom:1px solid #9c9c9c;">
  <ion-row>
    <ion-col class="numberCircle">1</ion-col>
    <ion-col>John Doe</ion-col>
    <ion-col>Posting</ion-col>
  </ion-row>
</ion-card-header>

css

.numberCircle {
        border-radius: 50%;
        width: 25px;
        height: 25px;
        padding: 4px;
    
        background: #fff;
        border: 2px solid #666;
        color: #666;
        text-align: center;
    
        font: 12px Arial, sans-serif;
    }

Solution

  • It is easier when you put the number in another element and center that

    ion-row.row {
        padding: 5px 26px;
        justify-content: space-between;
    }
    
    ion-row.row ion-col {
       flex-grow: 0;
    }
    
    .numberCircle {
        border-radius: 50%;
        width: 25px;
        height: 25px;
        display: inline-flex;
        background: #fff;
        border: 2px solid #666;
        flex-grow: 0;
        padding: 0;
    }
    
    .numberCircle span {
        color: #666;
        text-align: center;
        font: 12px Arial, sans-serif;
        width: 25px;
        display: inline-block;
        margin: auto;
    }
    <ion-card-header style="padding:0px;border-bottom:1px solid #9c9c9c;">
      <ion-row>
        <ion-col class="numberCircle">
          <span>
              1
          </span>
        </ion-col>
        <ion-col>John Doe</ion-col>
        <ion-col>Posting</ion-col>
      </ion-row>
    </ion-card-header>