如何使用 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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP