2014-01-23 47 views
0

在下面的代碼中,table應該低於div最終與它碰撞並顯示在它的中間。DIV與純HTML中的TABLE碰撞

任何幫助,歡迎。

小提琴here

<div id="header" width="100%"> 
    <center> 
     blabla 
    </center> 
    <table align="left" class="header"> 
     <tbody> 
      <tr> 
       <th>Links</th> 
      </tr> 
      <tr> 
       <td><a href="blabla">blabla</a></td> 
      </tr> 
      <tr> 
       <td><a href="blabl">blabla</a></td> 
      </tr> 
      <tr> 
       <td><a href="blabla">blabla</a></td> 
      </tr> 
     </tbody> 
    </table> 
    <table align="right" class="header">  
     <tbody> 
      <tr> 
       <th>contacts</th> 
      </tr> 
      <tr> 
       <td><a href="mailto:adude">this guy</a></td> 
      </tr> 
      <tr> 
       <td><a href="mailto:anotherdude">that other guy</a></td> 
      </tr> 
     </tbody> 
    </table> 
</div> 
<table> 
    <tbody> 
     <tr> 
      <th>the table that shouldn't be here</th> 
      <th></th> 
     </tr> 
    </tbody> 
</table> 

回答

3

你只需要「明確:既」當你不想要一個元素被其他元素的浮點值的影響(或者在這種情況下對齊)。

這是發生了什麼,你的第一張桌子附在左邊,第二張在右邊,第三張在兩者之間。

你可以告訴第三個表,找到一個空行,用style="clear: both"

工作fiddle here展開論述。

通知:

style = "clear: both" 

底部表

+0

非常感謝我的工作。 – Chapo

+0

我遇到了這樣的問題,即當我將邊框應用於包含'div'時,表格不再包含,但這是針對其他線程的。 – Chapo

0

幾件事情:

  1. 您使用<center>,它被廢棄了,according to W3C

    該元素是在HTML 3.2中引入的 - 塊元素。自從HTML 4 - 15.1.2對齊後,它已被棄用。

    HTML5將其歸類爲不符合要求的功能。

  2. 在你鏈接的jsfiddle中,表似乎低於div,所以 我不確定問題是什麼。你能澄清嗎?