如何在 JavaScript 中设置最后一行块或强制换行前一行在 "justify" 文本对齐下的对齐方式?


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

示例

你可以尝试运行以下代码,以返回当 “justify” 文本对齐的情况下如何通过 JavaScript 对齐最后一行块或强制换行前的一行 −

<!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>

更新于: 23-Jun-2020

334 次浏览

开启你的 职业生涯

通过完成课程获取认证

开始
广告
© . All rights reserved.