Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตั้งค่าการจัดวางแนวนอน (Horizontal Alignment) ขององค์ประกอบด้วย JavaScript

ใช้คุณสมบัติ cssFloat (ตรงกับ CSS float) เพื่อจัดวางองค์ประกอบชิดซ้ายหรือขวา ค่า left, right, none

ตัวอย่าง

<!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>