2009-12-23 142 views

回答

13

退房absolute positioning,也可能是z-index(儘管如果這是您唯一絕對定位的內容,您將不需要它)。儘管還有其他方法可以讓事情重疊,但這可能與您最相關。

很簡單的例子:

CSS:

#target { 
    position: absolute; 
    left: 50px; 
    top: 100px; 
    border: 2px solid black; 
    background-color: #ddd; 
} 

HTML:

<p>Something before the table</p> 
<div id="target">I'm on top of the table</div> 
<table> 
    <tbody> 
    <tr> 
     <td>Text in the table</td> 
     <td>Text in the table</td> 
    </tr> 
    <tr> 
     <td>Text in the table</td> 
     <td>Text in the table</td> 
    </tr> 
    <tr> 
     <td>Text in the table</td> 
     <td>Text in the table</td> 
    </tr> 
    <tr> 
     <td>Text in the table</td> 
     <td>Text in the table</td> 
    </tr> 
    </tbody> 
</table> 

Live copy | source

+0

現在鏈接不好現在 – davenpcj 2012-06-15 16:07:30

+2

@davenpcj:謝謝你讓我知道。我很震驚地發現,我*永遠*鏈接到該網站的第一位。已更新爲鏈接到W3C文檔,並添加了示例。 – 2012-06-15 16:17:34

0
浮法這在文本
<style> 
    #floatme{ 
     position: absolute; 
     top: XXpx; 
     left: XXpx; 
    } 
</style> 

只要改變頂部和左側的變量。

+2

仍然需要'z-index',這取決於它在標記中的位置,而不是它在最上面的東西。 – 2009-12-23 23:04:28

7

我會將表格封裝在「定位」格中。我將div設置爲position:relative,以便它不會中斷文檔內容的其餘部分。

<div style="position: relative"> 
    <table style="width: 500px;"> 
    <tr> 
     <td>Table Text</td> 
    </tr> 
    </table> 

    <div style="position: absolute; top: 0; left: 0; width: 500px; background: green;"> 
    I am on TOP of the table! 
    </div> 
</div> 
0

我同意TJ-z-index是要走的路 - 使用javascript和css/html將允許你在表上方隱藏/顯示這個「魔術浮動框」。