0

I have an href link that consists of some text and an image to the left of the text. The image is taller then the text and so the text currently displays at the top inline with the top of the image.

I want the text vertically centered. The padding doesn't work.

a.nav {
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size: 14px;
  color: yellow;
  text-decoration: none;
}

li.nav {
  line-height: 25px;
  display: block;
  padding-top: 15px;
}
<ul>
  <li class="nav">
    <img align="middle" src="https://placehold.it/100x100">
    <a class="nav" href="dashboard.cfm">Dashboard</a>
  </li>
</ul>
Turnip
  • 35,836
  • 15
  • 89
  • 111
Paul Hopkinson
  • 431
  • 1
  • 6
  • 14

3 Answers3

1

You Can Try This code

    a.nav {
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 14px;
      color: yellow;
      text-decoration: none;
      display:inline-block;
      vertical-align:middle
    }

    li.nav {
      line-height: 25px;
      display: block;
      padding-top: 15px;
    }
    li.nav img {
      display:inline-block;
      vertical-align:middle
    }
    <ul>
      <li class="nav">
        <img align="middle" src="media/images/dashboard.jpg">
        <a class="nav" href="dashboard.cfm">Dashboard</a>
      </li>
    </ul>
Md. Abu Sayed
  • 2,396
  • 2
  • 18
  • 26
0

Simply apply following style to your image.

<img align="middle" src="media/images/dashboard.jpg" style="vertical-align:middle;">
Charu Maheshwari
  • 1,583
  • 1
  • 8
  • 9
0

With vertical-align:middle - no need for padding at all

a.nav {
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size: 14px;
  text-decoration: none;
}

li.nav {
  line-height: 25px;
  display: block;
  vertical-align:middle;
}
<ul>
  <li class="nav">
    <img align="middle" src="http://www.fillmurray.com/140/100">
    <a class="nav" href="dashboard.cfm">Dashboard</a>
  </li>
</ul>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161