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

วิธีใช้ภาพลอย (Floating Image) ในหน้า HTML

เพื่อใช้ภาพลอย (floating image) ใน HTML ใช้คุณสมบัติ CSS float มันอนุญาตให้คุณลอยภาพไปทางซ้ายหรือขวา ค่า property เพิ่มเติมมีดังนี้:

Sr.No. Property Value & Description
1none
ไม่ลอย (ค่าเริ่มต้น)
2left
ลอยไปทางซ้าย
3right
ลอยไปทางขวา
4initial
ค่าเริ่มต้น

วิธีใช้ภาพลอย (Floating Image) ในหน้า HTML

ตัวอย่าง

<!DOCTYPE html> 
<html> 
  <head> 
    <title>HTML Floating Image</title> 
  </head> 
<body> 
  <h1>Float Right</h1> 
  <p>The below image floats to the right.</p> 
  <p> 
    <img src="https://www.tutorialspoint.com/green/images/logo.png" style="float:right" width="190" height="84" /> 
    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. This is demo text. This is demo text. This is demo text. This is demo text. 
  </p> 
  <h1>Float Left</h1> 
  <p>The below image floats to the left.</p> 
  <p> 
    <img src="https://www.tutorialspoint.com/green/images/logo.png" style="float:left" width="190" height="84" /> 
    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. This is demo text. This is demo text. This is demo text. This is demo text. 
  </p> 
</body> 
</html>

ผลลัพธ์

วิธีใช้ภาพลอย (Floating Image) ในหน้า HTML