HTML - DOM樣式物件columnWidth屬性



HTML DOM 樣式物件columnWidth屬性用於設定或獲取列的寬度。

語法

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

屬性值

描述
auto 這是預設值,瀏覽器確定列寬。
length 指定列的寬度。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

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

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

在下面的示例中,段落根據指定的列寬分成多列。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object columnWidth Property
    </title>
</head>
<body>
    <button onclick="fun()">Change</button>
    <br><br>
    <p id="width">
        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("width")
                .style.columnWidth = "150px";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
columnWidth 是 50 是 12 是 50 是 9 是 11.1
html_dom_style_object_reference.htm
廣告