DIV底部的中心图像

时间:2013-02-25 18:42:43

标签: css image html center

我发现了许多相关的问题,但似乎没有任何工作像我想要的那样。我想在我的DIV底部使用id =“bob”将图像居中。

我的HTML如下:

<table id="newsTable" width="100%" border="1">
  <thead>
     <tr>
       <th>
         <div onClick="openClose('2006')" style="cursor:hand; cursor:pointer">
              Title
              <img id="20062" src="images/play.png" style="float:right;">
         </div>
       </th>
     </tr>
   </thead>
   <tbody>
     <tr>
        <td>
          <div id="2006" class="texter">
            <h2>Subtitle</h2>
              <img src="images/image.jpg" style="float:right;">
              <p>
                Some text
              </p>
              <div class="album">
                <div class="album-content">
                  <img id="bob" src="images/picture.jpg">
                </div>
              </div>
              <img style="float:left;" id="prev" src="images/left.gif">
              <img style="float:right;" id="next" src="images/right.gif">
          </div>
        </td>
      </tr>
    </tbody>
  </table>

使用以下CSS样式:

#newsTable {
    border: 1px solid #e3e3e3;
    width: 100%;
    border-radius: 6px;
    -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
}

#newsTable td, #newsTable th {
    padding: 5px;
    color: #333;
}

#newsTable td {
    line-height: 20px;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 12px;
    border: 0px solid;  
    font-weight: bold;
}

#newsTable thead {
    font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    font-size:18px;
    padding: .2em 0 .2em .5em;
    text-align: left;
    color: #4B4B4B;
    background: transparant;
    border-bottom: solid 1px #999;
}

#newsTable th {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-image:url(images/background_thead.jpg);
    background-repeat: no-repeat; 
    font-size: 18px;
    line-height: 25px;
    font-style: normal;
    font-weight: normal;
    text-align: left;
    text-shadow: white 1px 1px 1px;
}

.texter {
    display:none
}

@media print {
    .texter {
       display:block;
    }
}

.album {
    height: 600px;
    position: relative;
}

.album-content {
    position: absolute;
    bottom: 0;
    float: none;
    text-align:center;
}

我已经尝试了几乎所有的东西,但似乎没有任何东西可以将id =“bob”的IMG移动到中心位置。任何人都可以告诉我哪个部分的CSS将图像保留在左边?

3 个答案:

答案 0 :(得分:1)

你的风格后遗漏了一句话:<img style="float:right; id="next" src="images/right.gif">

答案 1 :(得分:1)

您的.album-content div绝对定位,因此它不会采用其父容器的宽度,因此它只会与您的图像一样宽。您需要设置width或设置leftright属性:

<强>要么

.album-content {
    position   : absolute;
    bottom     : 0;
    left       : 0;
    right      : 0;
    text-align : center;
}

.album-content {
    position   : absolute;
    bottom     : 0;
    width      : 100%;
    text-align : center;
}

答案 2 :(得分:0)

@ user2108340像这样更改css

 .album-content {
    width:100%;
    position: absolute;
    bottom: 0;
    text-align:center;

    }