【问题标题】:trying to center an image in a ul vertically试图在 ul 中垂直居中图像
【发布时间】:2012-07-01 17:53:48
【问题描述】:

只是一个关于在水平 ul 导航中垂直居中图像的快速方法

http://i.imgur.com/GD7NQ.png

我希望 F 和 Twitter 垂直居中..

这是我的代码

<div id="nav" class="twelvecol last">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About Us</a></li>
            <li><a href="#">News</a></li>
            <li><a href="#">Gallery</a></li>
            <li><a href="#">Sponsors</a></li>
            <li><a href="#">Contact</a></li>
            <li><a href="#"><img src="images/fb.png"></a></li>
            <li><a href="#"><img src="images/twitter.png"></a></li>             
        </ul>   
    </div>

#nav
{


}

#nav ul
{
    height:60px;
    text-align:center;
    background: #cc0000; /* Old browsers */
    background: -moz-linear-gradient(top,  #cc0000 0%, #7c0000 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#cc0000), color-stop(100%,#7c0000)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  #cc0000 0%,#7c0000 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  #cc0000 0%,#7c0000 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  #cc0000 0%,#7c0000 100%); /* IE10+ */
    background: linear-gradient(to bottom,  #cc0000 0%,#7c0000 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cc0000', endColorstr='#7c0000',GradientType=0 ); /* IE6-9 */


}

#nav li
{
    display:inline-block;
    font-size:18px;

}

#nav li a
{
    color:#FFF;
    padding-top:20px;
    padding-left:20px;
    padding-right:20px;
    padding-bottom:20px;
    list-style-type:none;
    text-decoration:none;
}

#nav li a:hover{
    background:#F00;

}

感谢您提供的任何帮助

【问题讨论】:

    标签: css html-lists image


    【解决方案1】:

    对于 Facebook 和 Twitter 的图形链接,我个人会使用背景图片替换文本。

    背景图片意味着您可以简单地使用@987654321@ 和/或height 等来控制垂直放置。

    http://www.mezzoblue.com/tests/revised-image-replacement/ 列出了很多方法,我更喜欢使用text-indent

    【讨论】:

      猜你喜欢
      • 2018-07-07
      • 2010-12-30
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 2013-03-04
      • 2014-04-28
      相关资源
      最近更新 更多