高度和行高之間有什麼區別?


高度是容器的垂直度量,例如,div 的高度。

行高是 CSS 屬性,用於指定行高,即第一行文字頂部到第二行文字頂部的距離。它是兩段文字之間的空隙。

示例

你可以嘗試執行以下程式碼來學習高度和行高之間的區別

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         .height {
            height: 20px;
         }

         .lheight {
            line-height: 15px;
         }

         .lheightbigger {
            line-height: 35px;
         }
      </style>
   </head>
   <body>
      <h2>Height</h2>
      <div class="height">
         This is demo text. This is demo text.
         This is demo text. This is demo text.
         This is demo text. This is demo text.
      </div>

      <h2>Line Height with less space</h2>
      <div class="lheight">
         This is demo text showing line height example. This is demo text showing line height example.
         This is demo text showing line height example. This is demo text showing line height example.
         This is demo text showing line height example.This is demo text showing line height example.
      </div>

      <h2>Normal Text</h2>
    <div>
      This is normal text.
      This is normal text.
      This is normal text.
    </div>

    <h2>Line Height with more space</h2>
    <div class="lheightbigger">
      This is normal text. This is normal text.This is normal text.
      This is normal text. This is normal text.This is normal text.
      This is normal text. This is normal text.This is normal text.
    </div>
</body>
</html>

更新時間:2020 年 5 月 8 日

2 千次以上瀏覽

開啟你的 職業生涯

完成課程獲取證書

開始
廣告