0

How can I align text within an A tag relative to an image?? This is where I am stuck. No matter what I try, it always seems to align the text from the top border. I want the middle of the text centered relative to the middle of the image.

The problem seems to be that the image within the A tag is taller than the text, and no matter what, the text just sits at the baseline..

css:

.ty-bar {
  position: fixed;
  left: 0;
  right: 0;
  top: 32;
  height: 40px;
  background-color: #AAA;
  z-index: 50;
}

.ty-bar ul {
  list-style-type: none;
  margin: 8px;
  padding: 0;
  border: 1px solid green;
  vertical-align: middle;
}

.ty-bar-left {
  float: left;
}

.ty-bar-right {
  float: right;
}

html:

<div class="ty-bar">
  <ul class="ty-bar-left">
    <li>

      <a href="#">
        <img src="https://cdn4.iconfinder.com/data/icons/miu/24/circle-back-arrow-outline-stroke-32.png" width="24" height="24"> Back
      </a>

    </li>
  </ul>

  <ul class="ty-bar-right">
    <li>
      <img src="https://cdn2.iconfinder.com/data/icons/files-folders-3/24/files-folders-52-32.png" width="24" height="24">
    </li>
  </ul>
</div>
Tyler Collins
  • 127
  • 10

1 Answers1

2

add a vertical-align: middle; to the image.

JSfiddle

Here's an answer, you can read more but basically:

Since it's all in one line, it's really the image you want aligned, not the text.

Community
  • 1
  • 1
Amin Gharavi
  • 452
  • 3
  • 14