把我的形象放在ul li div里面

时间:2013-02-08 13:52:33

标签: html css

我在页脚中放置了一个图像,我想让它居中但我不会工作 我希望我的图像居中,所以我希望有人可以帮我看一下我的代码

HTML

<div class="center">
                <ul>
                    <li><a href="#" target="_blank" class="centering_"></a></li>

                </ul>
            </div>  

CSS:

.center 
{
    width: 84px;    
    margin: 0 auto;
}
.center ul 
{
    width: 209px;
    line-height: normal;  

}
.center ul li 
{
    float: left;
    margin-right: 11px;

}
.center ul li.last 
{
    margin-right: 0px;
}
.center ul li a
{   
    display: block;
    height: 33px;
    width: 33px;
}

.centering_ {background: transparent url('../images/hello.png') no-repeat;}

编辑: 以下是jsFiddle中的示例:http://jsfiddle.net/XJbaM/

在我的代码中,我的页脚中有两个图标,我想要的是删除页脚中右图标中心左侧图标,图标上方的文字已经居中

解决

2 个答案:

答案 0 :(得分:3)

像这样添加一个包装器div。

<div>
  <ul>
      <li>
          <div class="wrapper">
              <a href="img"></a>
          </div>
      </li>
  </ul>

和包装器的css:

.wrapper {
       margin:0 auto;
       width: /* how big your img is PX EM % etc */;
       text-align:center;
}

我在浏览器中测试了它并且工作正常。这是我使用的确切代码:你和我的混合

    <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
.center 
{
    width: 784px;    
    margin: 0 auto;
    border: 1px solid #000;
}
.center ul 
{
    width: 709px;
    line-height: normal;  

}
.center ul li 
{
    float: left;
    margin-right: 11px;
    border: 1px solid #000;
    width:500px;

}
.wrapper {
    margin:0 auto;
    width:500px;
    text-align:center;
}
.center ul li.last 
{
    margin-right: 0px;
}
.center ul li a
{   
    display:inline-block;
    height: 33px;
    width:100px;
}
.clear {
    clear:left;
}

.centering_ {background-image:url(img/activenav.png);
background-repeat:no-repeat;}
</style>
</head>

<body>
<div class="center">
                <ul>
                    <li><div class="wrapper"><a href="#" target="_blank" class="centering_"></a></div></li>

                </ul>
            <div class="clear">ss</div>
            </div>  
</body>
</html>

现在我的PIRATES BOOTY?

答案 1 :(得分:-5)

放置标签&lt;中心&gt;和&lt; / CENTER&gt;围绕整个div。它将以div为中心。

<CENTER>
<div class="center">
                <ul>
                    <li><a href="#" target="_blank" class="centering_"></a></li>

                </ul>
            </div>  
</CENTER>