Johann
Johann

Reputation: 12398

How to vertically align spans with text and image

I have now been looking for hours (obviously not in the right place!)

Please consider this sample: http://jsfiddle.net/DYLs4/9/

<div id="wrapper">
    <span id="text24">Text 24</span>
    <span id="text12">Text 12</span>
    <span id="icon"></span>
</div>

css:

#text24{
    font-size:24px; color:#999;   
}
#text12{
    font-size:12px; color:#000;  
}
#icon{
    height:36px; width:36px;
    display:inline-block;
    background:url(some-icon.png);
}​

Result

What I'm trying to achieve is this:

Goal

Many thanks for your help!

Upvotes: 11

Views: 37127

Answers (4)

slash197
slash197

Reputation: 9034

Add vertical-align: middle to your image.

EDIT

Per comments, this solution also requires display:inline-block;.

Upvotes: 26

cgvector
cgvector

Reputation: 929

This is working

http://jsfiddle.net/rizwanabbasi/frsA5/1/

Upvotes: 2

cgvector
cgvector

Reputation: 929

Final result

http://jsfiddle.net/rizwanabbasi/frsA5/

<div id="wrapper">
    <span id="text24">Text 24</span>
    <span id="text12">Text 12</span>
    <img src="http://www.adlittle.com/fileadmin/templates/images/rss_feed_icon.png" id="icon"/>
</div>

#wrapper{
    position:absolute; left:0;
}
#text24{
    font-size:24px; color:#999; font-weight:bold;
}
#text12{
    font-size:12px; color:#000; font-weight:bold; }
#icon{
    height:36px; width:36px;
    display:inline;
    vertical-align:middle;
    }

Upvotes: 0

Dewfy
Dewfy

Reputation: 23624

I know most of designers hate use table for layout, but let me try anyway. You can use valign of table.

Upvotes: 0

Related Questions