HTML - DOM Style 对象 textOverflow 属性



HTML DOM Style 对象**textOverflow**属性用于指定文本溢出包含元素时的行为。

语法

设置 textOverflow 属性
object.style.textOverflow= "clip | ellipsis | string | initial | inherit";
获取 textOverflow 属性
object.style.textOverflow;

属性值

描述
clip 这是默认值,它会裁剪文本。
ellipsis 它将裁剪的文本显示为省略号。
string 它用于呈现给定的字符串以显示裁剪的文本
initial 它用于将此属性设置为其默认值。
inherit 它用于继承其父元素的属性。

返回值

它返回一个字符串值,表示元素的文本溢出属性。

HTML DOM Style 对象“textOverflow”属性示例

以下示例将 div 元素的 textOverflow 属性设置为**ellipsis**。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object textOverflow Property
    </title>
    <style>
        #overflow {
            border: 1px solid black;
            background-color: #04af2f;
            color: whitesmoke;
            width: 150px;
            white-space: nowrap;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <p>
        Click to change set text overflow.
    </p>
    <button onclick="funTwo()">Ellipsis</button>
    <button onclick="fun()">Clip</button>    
    <div id="overflow">
        JavaScript is a lightweight, interpreted
        programming language. It is commonly used
        to create dynamic and interactive elements
        in web applications.
        <br>
        JavaScript is very easy to implement because
        it is integrated with HTML. It is open
        and cross-platform.
        <br>
        This JavaScript tutorial has been designed
        for beginners as well as working professionals
        to help them understand the basic to advanced
        concepts and functionalities of JavaScript.
        <br>
        It covers most of the important concepts
        related to JavaScript such as operators, control
        flow, functions, objects, OOPs, Asynchronous
        JavaScript, Events, DOM manipulation and much more.
    </div>
    <script>
        function funTwo() {
            document.getElementById("overflow")
                .style.textOverflow = "ellipsis";
        }
        function fun() {
            document.getElementById("overflow")
                .style.textOverflow = "clip";
        }
    </script>
</body>
</html>

支持的浏览器

属性 Chrome Edge Firefox Safari Opera
textOverflow 是 1 是 12 是 7 是 1.3 是 11
html_dom_style_object_reference.htm
广告