HTML - DOM Style 对象 columns 属性



HTML DOM Style 对象的 **columns** 属性是 `columnWidth` 和 `columnCount` 属性的简写属性,用于设置列宽和列数。

语法

设置 columns 属性
object.style.columns= "auto | column-width | column-count | initial | inherit";
获取 columns 属性
object.style.columns;

属性值

描述
auto 默认值,将列数和列宽都设置为 auto。
column-width 设置列宽。
column-count 指定元素将被分成多少列。
initial 将此属性设置为其默认值。
inherit 继承其父元素的属性值。

返回值

返回一个字符串值,表示元素的 columns 属性。

HTML DOM Style 对象 'columns' 属性示例

以下示例使用 columns 属性设置列宽并定义列数。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object columns Property
    </title>
</head>
<body>
    <p>Click to set column count and width.</p>
    <button onclick="fun()">Click</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.columns = "45px 4";
        }
    </script>
</body>
</html>

支持的浏览器

属性 Chrome Edge Firefox Safari Opera
columns 是 50 是 12 是 52 是 9 是 11.1
html_dom_style_object_reference.htm
广告
© . All rights reserved.