HTML - DOM樣式物件 captionSide 屬性



HTML DOM 樣式物件 captionSide 屬性設定或返回表格標題的位置。表格標題只能垂直定位在頂部或底部。

語法

設定 captionSide 屬性
object.style.captionSide= "top | bottom | initial | inherit";
獲取 captionSide 屬性
object.style.captionSide;

屬性值

描述
top 這是預設值,將表格標題設定在表格頂部。
bottom 將表格標題設定在表格底部。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示表格標題的位置。

HTML DOM 樣式物件“captionSide”屬性示例

以下示例將表格標題設定在表格的頂部和底部。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object captionSide Property
    </title>
    <style>
        table {
            border: aqua 2px solid;
        }
    </style>
</head>
<body>
    <p>
        Click to position the table caption.
    </p>
    <button onclick="funtwo()">Bottom</button>
    <button onclick="fun()">Top</button>
    <br><br><br><br>
    <table id="border" border="1">
        <caption>Table No. 21</caption>
        <tr>
            <td>This is</td>
            <td>is</td>
        </tr>
        <tr>
            <td>an example</td>
            <td>table</td>
        </tr>
        <tr>
            <td>for</td>
            <td>caption side</td>
        </tr>
    </table>
    <script>
        function funtwo() {
            document.getElementById("border")
                .style.captionSide = "bottom";
        }
        function fun() {
            document.getElementById("border")
                .style.captionSide = "top";
        }        
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
captionSide 是 1 是 12 是 1 是 1 是 4
html_dom_style_object_reference.htm
廣告