使用 CSS float 屬性對齊元素


如果要使用 CSS 中的 float 屬性對齊元素,可以嘗試執行以下程式碼 −

示例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         .demo {
            float: right;
            width: 200px;
            border: 1px dashed blue;
            padding: 5px;
         }
      </style>
   </head>
   <body>
      <h1>Heading</h1>
      <div class = "demo">
         <p>This is demo text and right aligned.</p>
      </div>
   </body>
</html>

輸出

更新時間:2020 年 6 月 22 日

132 次瀏覽

開啟您的職業生涯

完成課程認證

開始
廣告