如何使用 JavaScript 设置在 text-align 为“justify”时某个块体的最后一行或强制换行符前的一行的对齐方式?


在 JavaScript 中使用 textAlignLast  属性将最后一行设置为 right。将其设置为 right 并允许右对齐。

示例

你可以尝试运行以下代码返回如何使用 JavaScript 将 text-align 设置为“justify”时某个块体的最后一行或强制换行符前的一行的对齐方式 −

<!DOCTYPE html>
<html>
   <head>
      <style>
         #myDIV {
            text-align: justify;
         }
      </style>
   </head>

   <body>
      <div id = "myText">
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
      </div>
      <button onclick = "display()"> Set Alignment </button>
      <script>
         function display() {
            document.getElementById("myText").style.textAlignLast = "right";
            ;
         }
      </script>
   </body>
</html>

更新于:2020 年 6 月 23 日

334 浏览量

开启您的 职业

参加课程,获取认证

开始学习
广告
© . All rights reserved.