Strong Like Bull
Strong Like Bull

Reputation: 11297

How to vertically center images within an LI element?

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

Can someone kindly point me in the right direction since I am not a CSS expert by far. I know I can get them using tables but I do not want to do that. Thanks.

Oh and I am using EJS in the code below. Please see the screenshot:

Screenshot of list

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>

Upvotes: 6

Views: 17668

Answers (4)

<style>

.logo_bar {
display:inline-block;
vertical-align: middle;
}
.icon-align{
vertical-align: middle;
}
</style>
<ul>
<li class="logo_bar"><img class="icon-align" src="modal-box-icon/ok.svg" />
Menu 1
</li>
<li class="logo_bar"><img class="icon-align" src="modal-box-icon/ok.svg" />
Menu 1
</li>
<li class="logo_bar"><img class="icon-align" src="modal-box-icon/ok.svg" />
Menu 1
</li>
<li class="logo_bar"><img class="icon-align" src="modal-box-icon/ok.svg" />
Menu 1
</li>
</ul>

Upvotes: 0

tatty27
tatty27

Reputation: 1554

I know I'm late to the party but I always use this and thought 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;
}

Upvotes: 3

Rajdeep
Rajdeep

Reputation: 802

Just apply margin on 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

Upvotes: 0

jared_flack
jared_flack

Reputation: 1646

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;
}​

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

Upvotes: 12

Related Questions