Home > Software design >  Div does not center inside Div [duplicate]
Div does not center inside Div [duplicate]

Time:09-30

I am centering a number inside of a circle. The heading centers but the number does not:

.numberCircle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#inner {
  width: 50%;
  margin: 0 auto;
}
<div class="card">
  <div id="@(ViewBag.Id)" class="card-body" style="min-height: 495px;">
    <div style="text-align:center">
      <h2>My Number</h2>
    </div>
    <div id="inner">
      <div class="numberCircle" style="background:green;font-size:32px">2.98</div>
    </div>
  </div>
</div>

CodePudding user response:

Just add margin: 0 auto; to .numberCircle. That will center it inside the inner div.

.numberCircle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

#inner {
  width: 50%;
  margin: 0 auto;
}
<div class="card">
  <div id="@(ViewBag.Id)" class="card-body" style="min-height: 495px;">
    <div style="text-align:center">
      <h2>My Number</h2>
    </div>
    <div id="inner">
      <div class="numberCircle" style="background:green;font-size:32px">2.98</div>
    </div>
  </div>
</div>

  • Related