How to vertically center images inside an LI element?

I am using jQuery mobile and trying to center some of the image icons in the list. The problem I am facing is that the images are not vertically centered in the list item.

Can someone kindly point me in the right direction, since I'm not a CSS expert yet. I know that I can get them to use tables, but I don't want to do this. Thank.

Oh and I use EJS in the m code below. PLEASE SEE THE SCREEN SHOT:

http://imgur.com/uIXu C

Here is my code:

<li data-icon="false">
            <a href="#">
                <img src="images/img_trans.gif" class='largePlatform platform_<%= releases[i].platform_abbr %>_large' width='30' height='30' style="position:absolute; top:25%; left:10px"/>
                <h2 style="position:absolute; top:25%; left:50px"><%= releases[i].platform_abbr %></h2>

                 <div data-role="controlgroup" data-type="horizontal" style="float:right" >

                    <% if (purchaseText != "") { %>

                        <img src="images/game_detail/<%= releases[i].purchase_button_icon %>-purchase.png" width="35" height="35" onclick="window.open('<%= releases[i].purchase_button_url %>');" alt="<%= purchaseText %>" style="position:relative; top:10px;"/>

                    <% } %>

                    <div data-role="button" data-icon="reminder" data-theme="<%= buttonTheme %>" onclick="<%= buttonAction %>(<%= releases[i].id %>)">
                   <%= buttonText %>
               </div>
                </div>

            </a>
        </li>
+5
source share
3 answers

Live example :

http://jsfiddle.net/B6Z9N/

HTML

<li>
    <img src="http://dummyimage.com/20x20/000/000000.png" />
</li>โ€‹

CSS

li {
    border: 1px dotted black; /* Just to illustrate height */

    height: 100px;
    line-height: 100px;
    vertical-align: middle;
}โ€‹

: http://css-tricks.com/snippets/css/absolute-center-vertical-horizontal-an-image/

+9

margin img.

<li>
    <img class="image-style" src="https://dummyimage.com/20x20/000/111fed" />
</li>

.image-style {
   margin : 10px -10px;

}

li {
  border : 1px solid black
}

JSFiddle

0

I know I'm late for the party, but I always use it and thought that someone might find it useful.

HTML ..

<ul>
    <li class="logo_bar"><img src="img/1" /></li>
    <li class="logo_bar"><img src="img/2" /></li>
    <li class="logo_bar"><img src="img/3" /></li>
    <li class="logo_bar"><img src="img/4" /></li>
    <li class="logo_bar"><img src="img/5"/></li>
</ul>

CSS ...

.logo_bar {
    display: inline-block;
    vertical-align: middle;
}
0
source

All Articles