如何在 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.