HTML <table> 預設為 display: table,屬於正常文件流,無法自由定位。只要為表格設定 CSS position: absolute(或 fixed),即可脫離文件流,像 AP Div(圖層)一樣在設計視圖中自由拖曳定位。
f1)。+)。ID(或「進階」輸入 #f1)。This document only 或外部樣式表。absolute(絕對定位)。100px(距離包含區塊左邊緣)。50px(距離包含區塊上邊緣)。Width、Height、Z-Index(堆疊順序)。





<!-- HTML -->
<table id="f1" style="position: absolute; left: 100px; top: 50px; z-index: 10;">
<tr><td>表格內容</td></tr>
</table>
<!-- 或外部 CSS -->
<style>
#f1 { position: absolute; left: 100px; top: 50px; z-index: 10; }
</style>
<table id="f1">...</table>
position: absolute 相對於最近的已定位祖先元素(position: relative/absolute/fixed),若無則相對 <body>(初始包含區塊)。<div style="position: relative"> 內,left/top 以該 div 為基準。position: fixed 相對於視窗,捲動不移動,適合固定版頭/浮動工具列。| 場景 | 定位類型 | 關鍵設定 |
|---|---|---|
| 浮動側邊欄/工具箱 | fixed | right: 0; top: 50%; transform: translateY(-50%); z-index: 9999; |
| 彈出式模擬對話框 | absolute | 置中:left: 50%; top: 50%; transform: translate(-50%, -50%); |
| 儀表板拖曳排版 | absolute | 搭配 JS mousedown/move/up 更新 left/top 實現拖曳 |
| 固定頁首/頁尾 | fixed | top: 0; left: 0; width: 100%; / bottom: 0; |
margin 撐開空間。left/top 在螢幕寬度變化時可能跑版。配合媒體查詢調整位置,或改用 Flex/Grid 佈局。<script>
var table = document.getElementById('f1');
var isDragging = false, offsetX, offsetY;
table.addEventListener('mousedown', function(e) {
if (e.target.tagName === 'TABLE' || e.target.tagName === 'TH' || e.target.tagName === 'TD') {
isDragging = true;
offsetX = e.clientX - table.offsetLeft;
offsetY = e.clientY - table.offsetTop;
table.style.cursor = 'grabbing';
}
});
document.addEventListener('mousemove', function(e) {
if (!isDragging) return;
table.style.left = (e.clientX - offsetX) + 'px';
table.style.top = (e.clientY - offsetY) + 'px';
});
document.addEventListener('mouseup', function() {
isDragging = false;
table.style.cursor = 'grab';
});
</script>
為表格加上 position: absolute 即可在 Dreamweaver 設計視圖中像圖層般自由拖曳,極大提升版面微調效率。理解包含區塊、脫離文件流、Z-Index 管理等核心概念,並輔以響應式策略與無障礙考量,才能在實戰專案中穩健應用此技巧。