0

I'm trying to get this text to center in this div. I'm using react so the class name is "className"

.cartCost {
  background-color: #fffbe3;
  width: 300px;
  height: 40px;
  font-size: 24px;
  font-weight: bold;
  border: 1px solid #d9d9d9;
  border-radius: 2px;
  margin: 8px 0 5px 0;
}

.cartType {
  width: 50%;
  margin: 0 auto;
}
<div class="cartCost">
  <div class="cartType">$0.00</div>
</div>

The result is this: enter image description here

The text appears to the left not centered.

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
FabricioG
  • 3,107
  • 6
  • 35
  • 74

1 Answers1

1

Use text-align: center on your element. Otherwise the text is always left aligned by default.

.cartCost {
  background-color: #fffbe3;
  width: 300px;
  height: 40px;
  font-size: 24px;
  font-weight: bold;
  border: 1px solid #d9d9d9;
  border-radius: 2px;
  margin: 8px 0 5px 0;
  text-align: center;
}

.cartType {
  width: 50%;
  margin: 0 auto;
}
<div class="cartCost">
  <div class="cartType">$0.00</div>
</div>
Terry
  • 63,248
  • 15
  • 96
  • 118