HTML - DOM Style 物件 bottom 屬性



HTML DOM Style 物件 **bottom** 屬性設定或返回定位元素的底部位置。它還指定邊距、填充、捲軸和邊框。

定位元素是指其 position 屬性設定為 fixed、relative 或 absolute 的元素。

語法

設定 bottom 屬性
object.style.bottom= "auto | length | percentage | initial | inherit";
獲取 bottom 屬性
object.style.bottom;

屬性值

描述
auto 這是預設值,瀏覽器會設定底部位置。
length 它使用畫素和其他 CSS 測量單位設定底部位置。
percentage 它使用百分比值設定底部位置。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示定位元素的底部位置。

HTML DOM Style 物件“bottom”屬性示例

以下示例使用 length 和 percentage 設定 p 元素的底部位置。這裡我們使用了絕對定位。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object bottom Property
    </title>
    <style>
        #para {
            position: absolute;
        }
    </style>
</head>
<body>
    <button onclick="fun()">Length</button>
    <button onclick="funTwo()">Percentage</button>
    <p id="para">Click to set the value to 50px</p>
    <script>
        function fun() {
            document.getElementById("para")
                .style.bottom = "50px";
        }
        function funTwo() {
            document.getElementById("para")
                .style.bottom = "28%";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
bottom 是 1 是 12 是 1 是 1 是 6
html_dom_style_object_reference.htm
廣告