要设置缩进,请使用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>