Lately I've been working with Japanese text, and I've found a rather annoying property. In Japanese, unlike English, glyphs do not extend below the text baseline. This example should show what I mean:
div {
font-size: 72pt;
display: inline-block;
text-decoration: underline;
border: 1px solid red;
margin: 10px;
text-align: center;
}
<div lang="ja">日本語</div>
<div lang="en">English</div>
Notice how the "g" in "English" extends below the underline, but none of the characters in 日本語 do. This is typical of Japanese text. Despite this, space is still reserved below the underline, and in fact on my screen the Japanese text reserves more space than the English text does. My question is this:
Is there a way to remove this space with CSS which is reliable across changing fonts and font sizes? I can see at least two possible approaches:
You need to reset the line-height
so it's not bigger than 1. The initial value is normal
which depends on the User Agent of the browser, on the font-family and on the font-size, but it's some number between 1 and 1.2 in general. Here's more information if you're interested.
div {
font-size: 72pt;
display: inline-block;
text-decoration: underline;
border: 1px solid red;
margin: 10px;
text-align: center;
line-height: 1;
}
<div lang="ja">日本語</div>
<div lang="en">English</div>
Just set the line height to the same size as the font size: line-height: 72pt
. This normalizes the space that's taken for the font height. Of course you can take every value for the line height that you like, to adjust that space. More information to line-height
at MDN.
div {
font-size: 72pt;
line-height: 72pt;
display: inline-block;
text-decoration: underline;
border: 1px solid red;
margin: 10px;
text-align: center;
}
<div lang="ja">日本語</div>
<div lang="en">English</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With