How to vertically align spans with text and image

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 17:23:09

问题


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

What I'm trying to achieve is this:

  • Center vertically the text24 (relative to the image)
  • Align the bottom of text12 with bottom of text24
  • Make sure the whole thing work in IE6 -> chrome

Many thanks for your help!


回答1:


Add vertical-align: middle to your image.

EDIT

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




回答2:


This is working

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




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/10615365/how-to-vertically-align-spans-with-text-and-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!