HTML - DOM樣式物件flexWrap屬性



HTML DOM 樣式物件 **flexWrap** 屬性指定彈性專案是否應該換行。

語法

設定 flexWrap 屬性
object.style.flexWrap= "nowrap | wrap | wrap-reverse | initial | inherit";
獲取 flexWrap 屬性
object.style.flexWrap;

屬性值

描述
nowrap 這是預設值,指定彈性專案不會換行。
wrap 指定彈性專案在需要時會換行。
wrap-reverse 指定彈性專案在需要時會反向換行。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素的 flex-wrap 屬性。

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

以下示例演示了“wrap”、“nowrap”和“wrap-reverse”屬性值。

<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        #flex {
            width: 300px;
            height: 300px;
            border: 1px solid black;
            display: flex;
        }
        #flex div {
            height: 80px;
            width: 80px;
        }
    </style>
    <title>
        HTML DOM Style Object flexWrap Property
    </title>
</head>
<body>
    <p>Click to apply flexWrap property.</p>
    <button onclick="fun()">Wrap</button>
    <button onclick="funTwo()">No Wrap</button>
    <button onclick="funThree()">Wrap-Reverse</button>
    <br>
    <br>
    <div id="flex">
        <div style="background-color: #04af2f;">1</div>
        <div style="background-color: aqua;">2</div>
        <div style="background-color: yellow;">3</div>
        <div style="background-color: whitesmoke">4</div>
        <div style="background-color: black;">5</div>
    </div>
    <script>
        function fun() {
            document.getElementById("flex")
                .style.flexWrap = "wrap"
        }
        function funTwo() {
            document.getElementById("flex")
                .style.flexWrap = "nowrap"
        }
        function funThree() {
            document.getElementById("flex")
                .style.flexWrap = "wrap-reverse"
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
flexWrap 是 29 是 12 是 28 是 9 是 16
html_dom_style_object_reference.htm
廣告