如何用浮動圖片 in HTML page?


要在 HTML 中使用浮動圖片,請使用 CSS 屬性 float。它允許你使影像向左或向右浮動。更多屬性值包括以下內容

序號
屬性值和說明
1
none

不浮動
2
left

向左浮動
3
right

向右浮動
4
initial

預設值

示例

你可以嘗試執行以下程式碼,以便在 HTML 中使用浮動圖片。以下是 float right 和 float left CSS 屬性的用法

<!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://tutorialspoint.tw/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.
      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://tutorialspoint.tw/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.
         This is demo text. This is demo text.
         This is demo text. This is demo text.
      </p>
   </body>
</html>

輸出

更新日期:2021 年 12 月 22 日

20K+ 瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.