Computer >> Máy Tính >  >> Lập trình >> Javascript

Làm cách nào để đặt căn chỉnh theo chiều ngang của một phần tử bằng JavaScript?


Để căn chỉnh phần tử theo chiều ngang, hãy sử dụng cssFloat tài sản.

Ví dụ

Bạn có thể thử chạy mã sau để đặt căn chỉnh theo chiều ngang của một phần tử bằng JavaScript -

<!DOCTYPE html>
<html>
   <body>
      <img id="myID" src="https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg" width="300" height="300">
      <p>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.
      </p>
      <button type="button" onclick="display()">Align Horizontally</button>
      <script>
         function display() {
            document.getElementById("myID").style.cssFloat = "right";
         }
      </script>
   </body>
</html>