HTML - DOM Style 物件 columnCount 屬性



HTML DOM Style 物件的 **columnCount** 屬性用於指定元素應分成多少列。

語法

設定 columnCount 屬性
object.style.columnCount= "number | auto | initial | inherit";

獲取 columnCount 屬性
object.style.columnCount;

屬性值

描述
數字 它指定元素應分成多少列。
auto 它是預設值,取決於其他屬性。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

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

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

在以下示例中,我們將元素分成了三列和四列。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object columnCount Property
    </title>
</head>
<body>
    <button onclick="fun()">Three Column</button>
    <button onclick="funTwo()">Four Column</button>
    <p id="color">
        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. 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>
    <script>
        function fun() {
            document.getElementById("color")
                .style.columnCount = "3";
        }
        function funTwo() {
            document.getElementById("color")
                .style.columnCount = "4";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
columnCount 是 50 是 12 是 52 是 9 是 37
html_dom_style_object_reference.htm
廣告