【问题标题】:Three separate tables that sit left to right next to each other centered三张单独的桌子,从左到右并排,居中
【发布时间】:2013-05-27 04:30:03
【问题描述】:

我试图让一系列桌子从左到右并排放置,同时居中。

<div>
<table border="1px"; style="float:left";>
    <!--left side Advertisement-->
    <tr>
        <td>
            <p><img src="http://www.radiorebel.net/wp-content/uploads/2013/02/RadioRebelJamMaestroAd.png"></p>
        </td>
    </tr>    
</table>

<!--Player Table Collective-->
<table border="1px"; width="500"; height="500"; style="float:left";">
    <td>
        <!--Wavestreaming.com online Status-->
        <p>Status: <span data-shoutcast-value="status"></span></p>
        <!--Wavestreaming Song Title-->
        <p>Now Playing: <span data-shoutcast-value="songtitle"></span></p>
    </td>
    <td>
        <!--Album Art and PlayerTable-->
        <p>Album Art goes here</p>
        <p>Player goes here</p>
    <!--Third Table in the Player Collective-->
    </td>
    <td>
        <p>Stuff</p>
            </br>
        <p>stuff 2</p>
            </br>
        <p>stuff 3</p>
    </td>
</table>

<!--right side advert-->
<table border="1px"; style="float:left">
    <td>
        <p><img src="http://www.radiorebel.net/wp-content/uploads/2013/02/RadioRebelJamMaestroAd.png"></p>
    </td>
</table>

通过在我的桌子上使用float:left,我能够让它们挨着坐,但我无法使桌子居中。我尝试将所有内容包装在一个 div 中并告诉 to 将所有内容居中,但这似乎不起作用。任何帮助表示赞赏!

【问题讨论】:

    标签: html html-table center


    【解决方案1】:

    尝试将第一个 div 更改为:

    <div style='position: absolute; width: 80%; left:50%; margin-left: -40%;'>
    

    只要 margin-left 是 - 宽度的一半,这应该可以工作。

    【讨论】:

      【解决方案2】:

      使用display:inline-block 而不是float:left。 然后在封闭的 div 上使用 div 样式text-align=center。 还需要将vertical-align=top 添加到每个表格样式中。 看这里: http://jsfiddle.net/KJhhc/

      【讨论】:

      • Stan,请看看您是否可以对适合您的答案投票。我们非常重视 stackoverflow 社区中的投票。也请将您选择的解决方案“标记为答案”。
      【解决方案3】:

      概念是设置&lt;div&gt;的宽度,并指定margin-left和margin-right为auto。

      <!DOCTYPE html>
      <html lang="en-US">
      <body>
      <div style="width:1020px; margin:0 auto;">
      <table border="1" style="float:left">
          <!--left side Advertisement-->
          <tr>
              <td>
                  <p><img src="http://www.radiorebel.net/wp-content/uploads/2013/02/RadioRebelJamMaestroAd.png"></p>
              </td>
          </tr>    
      </table>
      
      <!--Player Table Collective-->
      <table border="1" width="500" height="500" style="float:left">
          <td>
              <!--Wavestreaming.com online Status-->
              <p>Status: <span data-shoutcast-value="status"></span></p>
              <!--Wavestreaming Song Title-->
              <p>Now Playing: <span data-shoutcast-value="songtitle"></span></p>
          </td>
          <td>
              <!--Album Art and PlayerTable-->
              <p>Album Art goes here</p>
              <p>Player goes here</p>
          <!--Third Table in the Player Collective-->
          </td>
          <td>
              <p>Stuff</p>
                  </br>
              <p>stuff 2</p>
                  </br>
              <p>stuff 3</p>
          </td>
      </table>
      
      <!--right side advert-->
      <table border="1" style="float:left">
          <td>
              <p><img src="http://www.radiorebel.net/wp-content/uploads/2013/02/RadioRebelJamMaestroAd.png"></p>
          </td>
      </table>
      </body>
      </html>
      

      【讨论】:

      • 这对我有用,谢谢!这是我第一次在互联网上寻求代码帮助,我并不失望。再次感谢!
      猜你喜欢
      • 1970-01-01
      • 2014-06-28
      • 1970-01-01
      • 2013-06-21
      • 1970-01-01
      • 2017-04-04
      • 2011-10-09
      • 2020-07-29
      相关资源
      最近更新 更多