CSS規範指出,應通過將指定值除以2並將結果應用於文本行的上方和下方來將行高應用於文本。傳統領先和CSS行高
這與領先的傳統理解有很大不同,這通常意味着間距只在文本行上方「添加」。 (我知道這不是100%正確的,因爲實際上線高不會增加空間,但會設置線的高度;但是,這樣可以更簡單地描述問題)。
考慮這個例子標記:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
p
{
margin:0;
font-size: 13pt;
line-height: 15pt;
}
h1
{
margin:0;
font-size: 21pt;
line-height: 30pt;
}
</style>
</head>
<body>
<h1>Title</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p>
<p>Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
<p>It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>
</body>
</html>
如果行高爲等於領先,則<h1>
和第一<p>
之間距離的傳統認識是等於<p>
的之間的距離,因爲該距離由領導定義。然而,這種情況並非如此。
雖然<p>
S之間的距離保持一致(p's line-height - p's font-size = 15 - 13 = 2pt
),距離<h1>
和第一<p>
之間是不同的:它等於(p's line-height - p's font-size)/2 + (h1's line-height - h1's font-size)/2 = (15 - 13)/2 + (30-21)/2 = 5.5pt
。
如果使用瀏覽器處理上述標記,可以很容易地用肉眼注意到。
問題在於,在頁面上保持垂直視覺節奏的傳統方式是通過設置基數領先的倍數的元素的領先。如上所示,該方法在CSS中不適用。
我有3個問題:
- 是我行高度的認識,領導和他們之間的分歧是否正確?
- 有沒有一種方法來保持與CSS的垂直節奏(通過模仿傳統領先與CSS或不)?
- (獎金問題)背後的高度與領先水平如此不同的原因是什麼?
更新:非常感謝您的意見!請注意,我建議我自己的解決方案,我會爲它的任何意見非常感謝:https://stackoverflow.com/a/8335230/710356
謝謝!但是,您鏈接的演示程序似乎是空的gif文件。另外,我在代碼中看不到任何負值。 – sbichenko
對不起,我修復了鏈接,並記住我沒有使用負值。 :-) – bookcasey
實際上,您不需要使用定位來保持垂直節奏。可以通過確保一致的行高(相對於字體大小)和底部邊距來完成。 – joshnh