HTML - DOM Style 物件 textAlignLast 屬性



HTML DOM Style 物件的 **textAlignLast** 屬性設定或返回文字最後一行對齊方式。

語法

設定 textAlignLast 屬性
object.style.textAlignLast= "auto | left | right | center | justify | start | end | initial | inherit";
獲取 textAlignLast 屬性
object.style.textAlignLast;

屬性值

描述
auto 這是預設值,其中最後一行是兩端對齊並向左對齊。
left 它將最後一行文字向左對齊。
right 它將最後一行文字向右對齊。
center 它將最後一行文字居中對齊。
justify 透過插入空白來填充整個寬度,使最後一行兩端對齊。
start 它將最後一行文字對齊到行的開頭,即如果文字方向為 ltr(從左到右),則為左對齊;如果文字方向為 rtl(從右到左),則為右對齊。
end 它將最後一行文字對齊到行的末尾,即如果文字方向為 ltr(從左到右),則為右對齊;如果文字方向為 rtl(從右到左),則為左對齊。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素的文字最後一行對齊屬性。

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

以下示例在方向為 ltr(從左到右)和 rtl(從右到左)時設定最後一行文字的對齊方式。

設定最後一行文字對齊方式

以下示例在方向為 ltr(從左到右)時將最後一行文字的對齊方式設定為 **right**、**center**、**justify** 和 **end**。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object textAlignLast Property
    </title>
    <style>
        #align {
            border: 1px solid #04af2f;
            text-align: justify;
        }
    </style>
</head>
<body>
    <p>Click to change last line text alignment.</p>
    <button onclick="fun()">Right Align</button>
    <button onclick="funTwo()">Center Align</button>
    <button onclick="funThree()">Justify Align</button>
    <button onclick="funFour()">End</button>
    <div id="align">
        <p>
            JavaScript is a lightweight, interpreted
            programming language. It is commonly used
            to create dynamic and interactive elements
            in web applications. JavaScript is very easy
            to implement because it is integrated with
            HTML. It is open and cross-platform.
            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.
            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.
        </p>
    </div>
    <script>
        function fun() {
            document.getElementById("align")
                .style.textAlignLast = "right"
        }
        function funTwo() {
            document.getElementById("align")
                .style.textAlignLast = "center"
        }
        function funThree() {
            document.getElementById("align")
                .style.textAlignLast = "justify"
        }  
        function funFour() {
            document.getElementById("align")
                .style.textAlignLast = "end"
        }      
    </script>
</body>
</html>

設定最後一行文字對齊方式

以下示例在方向為 trl(從右到左)時將最後一行文字的對齊方式設定為 **start** 和 **justify**。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object textAlignLast Property
    </title>
    <style>
        #align {
            border: 1px solid #04af2f;
            text-align: justify;
            direction: rtl;
        }
    </style>
</head>
<body>
    <p>Click to change last line text alignment.</p>
    <button onclick="funThree()">Justify Align</button>
    <button onclick="funFour()">Start</button>
    <div id="align">
        <p>
            JavaScript is a lightweight, interpreted
            programming language. It is commonly used
            to create dynamic and interactive elements
            in web applications. JavaScript is very easy
            to implement because it is integrated with
            HTML. It is open and cross-platform.
            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.
            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.
        </p>
    </div>
    <script>
        function funThree() {
            document.getElementById("align")
                .style.textAlignLast = "justify"
        }  
        function funFour() {
            document.getElementById("align")
                .style.textAlignLast = "start"
        }      
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
textAlignLast 是 47 是 12 是 49 是 16 是 34
html_dom_style_object_reference.htm
廣告