위치를 설정하려면 위치 를 사용하십시오. JavaScript의 속성. 다음 코드를 실행하여 JavaScript로 요소에 사용되는 위치 지정 방법 유형을 설정할 수 있습니다 -
예시
<!DOCTYPE html> <html> <head> <style> #box { width: 350px; height: 200px; background-color: orange; border: 3px solid red; position: relative; top: 20px; } </style> </head> <body> <p>Click to set the type of positioning method using position property.</p> <button type = "button" onclick = "display()">Set Position</button> <div id = "box"> <p>This is a div. This is a div. This is a div. This is a div. This is a div.<p> <p>This is a div. This is a div. This is a div. This is a div. This is a div.<p> <p>This is a div. This is a div. This is a div. This is a div. This is a div.<p> </div> <br> <br> <script> function display() { document.getElementById("box").style.position = "absolute"; } </script> </body> </html>