How to vertically align items in horizontally ul list with images?

僤鯓⒐⒋嵵緔 提交于 2019-12-07 03:46:05

问题


I have the following html code:

<div id="footer">
    <ul id="yw1">
        <li><a href="/index.php/site/login">About</a></li>
        <li><a href="/index.php/site/login">FAQ</a></li>
        <li><a href="http://twitter.com"><img src="/images/twitter_icon.png" /></a></li>
        <li><a href="http://twitter.com"><img src="/images/facebook_icon.png" /></a></li>
    </ul>       
</div>

And the following CSS styles:

#footer {
    margin-top: 25px;
    background: #000000 url(images/background.png) repeat;
    padding: 25px;
    box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, .2);
}
#footer ul {
    margin: 0;
    padding: 0px 0px 0px 0px;
    list-style: none;
    line-height: normal;
}
#footer li {
    padding-left: 20px;
    display: inline;
    list-style-type: none;
}
#footer a {
    color:white;
    letter-spacing: 1px;
    text-decoration: none;
    text-align: center;
    font-size: 14px;
    font-weight: 300;
}

Now result is:

But I need to align images and text links by vertically. How can I do it?


回答1:


As img tag is inline by default, it vertically aligns to the baseline and hence you need to use vertical-align: middle; for your img tag

Demo

CSS

#footer img {
    vertical-align: middle;
}



回答2:


User following CSS.

li { display:inline-block; vertical-align:middle }



回答3:


You just need vertical-align: middle on #footer li and #footer a + display: inline-block on images:

#footer li {
    /* ... */
    display: inline;
    vertical-align: middle;
}
#footer a {
    /* ... */
    vertical-align: middle;
    display: inline-block;
}

http://jsfiddle.net/dfsq/7kssu/




回答4:


Just change your css

from

line-height:normal

to

line-height:30px


来源:https://stackoverflow.com/questions/16209363/how-to-vertically-align-items-in-horizontally-ul-list-with-images

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