0

I have HTML code and I want to align content in li-element. I have image and text info in the li-element.

I tried vertical-align: middle for li-element, but it doesn't work

li img {
  float: left;
  display: block;
  margin-right: 20px;
  margin-bottom: 15px;
  width: 75px;
  height: 75px;
}
<ul>
  <li>
    <img src="images/1.jpg" alt="">
    <a class="post-title" href="#">Lorem Ipsum</a>
    <p class="post-date">March 05, 2015</p>
  </li>
  <li>
    <img src="images/1.jpg" alt="">
    <a class="post-title" href="#">Lorem Ipsum</a>
    <p class="post-date">March 05, 2015</p>
  </li>
</ul>
insertusernamehere
  • 21,742
  • 7
  • 80
  • 113
name name2
  • 113
  • 2
  • 10

1 Answers1

0

You could alter your HTML slightly and use the display:table-cell trick. Flexbox might something to look into as well, thought it's not as widely supported yet.

HTML

<ul>
    <li>
        <div>
            <img src="images/1.jpg" alt="">
            <a class="post-title" href="#">Lorem Ipsum</a>
            <p class="post-date">March 05, 2015</p>
        </div>
    </li>
    <li>
        <div>
            <img src="images/1.jpg" alt="">
            <a class="post-title" href="#">Lorem Ipsum</a>
            <p class="post-date">March 05, 2015</p>
        </div>
    </li>
</ul>

CSS

li div {  
    height: 200px; /*or whatever you need */
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}

fiddle example

mituw16
  • 4,934
  • 2
  • 18
  • 40