Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Cách dùng ảnh nổi (floating image) trong trang HTML

Giới thiệu

Để dùng ảnh nổi (floating image) trong HTML, dùng thuộc tính CSS float. Nó cho phép nổi ảnh sang trái hoặc phải. Các giá trị thuộc tính khác:

Giá trị Mô tả
noneKhông nổi (mặc định)
leftNổi sang trái
rightNổi sang phải
initialGiá trị mặc định

Cách dùng ảnh nổi (floating image) trong trang HTML

Ví dụ

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

Kết quả

Cách dùng ảnh nổi (floating image) trong trang HTML