如何使用JavaScript设置文本第一行的缩进?
要设置缩进,请使用textIndent 属性。
示例
您可以尝试运行以下代码以使用JavaScript返回文本第一行的缩进-
<!DOCTYPE html> <html> <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. </div> <br> <button onclick = "display()">Set Text Indent</button> <script> function display() { document.getElementById("myText").style.textIndent = "50px"; } </script> </body> </html>