HTML - DOM樣式物件minHeight屬性



HTML DOM 樣式物件 **minHeight** 屬性設定或返回元素的最小高度。它隻影響塊級元素或具有固定或絕對定位的元素。

語法

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

屬性值

描述
長度單位 (length) 指定元素的最小高度,以長度單位表示。
百分比 (percentage) 指定元素的最小高度,為父元素高度的百分比。
初始值 (initial) 將此屬性設定為其預設值。
繼承 (inherit) 繼承其父元素的屬性值。

返回值

返回一個字串值,表示元素的最小高度。

HTML DOM 樣式物件 'minHeight' 屬性示例

下面的示例將 div 元素的最小高度設定為 400px。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object minHeight Property
    </title>
    <style>
        #margin {
            border: 2px solid #04af2f;
            overflow: auto;
            width: 400px;
        }
    </style>
</head>
<body>
    <h3>
        Click to set minimum height.
    </h3>
    <button onclick="fun()">Set min Height</button>
    <br>
    <div id="margin">
        <p>
            CSS is the acronym for "Cascading 
            Style Sheet". It's a style sheet 
            language used for describing the 
            presentation of a document written 
            in a markup language like HTML. 
        </p>
        <p>
            CSS helps the web developers to 
            control the layout and other visual 
            aspects of the web pages. CSS plays 
            a crucial role in modern web development 
            by providing the tools necessary to 
            create visually appealing, accessible,
            and responsive websites.
        </p>
    </div>
    <script>
        function fun() {
            document.getElementById("margin")
                .style.minHeight = "400px";
        }
    </script>
</body>
</html>

支援的瀏覽器

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