如何使用 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 瀏覽量

開啟您的 職業

參加課程,獲取認證

開始學習
廣告