【问题标题】:Center image at bottom of DIVDIV 底部的中心图像
【发布时间】:2013-02-11 00:21:54
【问题描述】:

我发现了很多相关的问题,但似乎没有像我想要的那样工作。我想将 id="bob" 的图像居中放在我的 DIV 底部。

我的 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 的哪一部分将图像保持在左侧?

【问题讨论】:

  • 我更新了我的答案请检查

标签: css image html center


【解决方案1】:

你的风格后面缺少一个引用:&lt;img style="float:right; id="next" src="images/right.gif"&gt;

【讨论】:

  • 谢谢!但它并没有解决我的问题,实际上,在我“清理”我的代码并将其发布到此处后,引用丢失了。 (删除了 onClick 事件以使其更具可读性)
  • 好吧,看看我的其他答案。
【解决方案2】:

您的.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;
}

【讨论】:

  • 谢谢!从来没有这样想过,但我明白!
【解决方案3】:

@user2108340 像这样更改 css

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

    }

【讨论】:

  • @AlienWebguy 它的工作现在我检查了我的 html 页面
猜你喜欢
  • 2015-04-05
  • 2014-08-05
  • 1970-01-01
  • 2014-04-05
  • 2013-11-12
  • 1970-01-01
  • 2015-11-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多