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