0

I'm trying to align text to center (vertically and horizontally):

  <div class="panel-small sport">
    <b>Sport and Activity</b>
  </div>

this is the css:

.panel-small *
{
  text-align: center;
  vertical-align: middle;
}

.sport
{
  background-image: url("../img/sport.png");
 left: 248px;
}

the text appear even on top

Charanoglu
  • 1,229
  • 2
  • 11
  • 30

2 Answers2

1

Try flex positioning:

display: flex;
justify-content: center;
align-items: center;
billy.farroll
  • 1,903
  • 2
  • 15
  • 23
0

You can check this trick:

CSS:

text-align: center;
vertical-align: middle;
line-height: 90px;  /* the same as your div height */

Here is the complete explanation: https://stackoverflow.com/a/5703632/5655917

Or you can use Flexbox with this:

CSS:

.panel-small *{
    display: flex;
    justify-content: center;
    align-items: center;
}

Here more explanation: https://tutorialzine.com/2015/09/quick-tip-the-simplest-way-to-center-elements-vertically-and-horizontally

Regards!

Radames E. Hernandez
  • 4,235
  • 27
  • 37