当 JavaScript 中的 text-align 为"justify"时,如何设置块的最后一行或强制换行符之前的行的对齐方式?

javascriptobject oriented programmingfront end technology更新于 2024/6/21 17:16:17

使用 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>

相关文章


有用资源