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
廣告