8
I am trying to put together a layout as "pixel Perfect" as possible, but I have always come across this problem, using large fonts, there is a space above and below the font, as if it were a padding/margin. I searched on the subject, trying to relate to the line-height, but without success. Does anyone have any explanation of how to get as close to the font size?
From what I saw the "way" is to use the negative line-height and try to adjust, but each source would have a different negative line-height. I was also suggested to look more about the "vertical Rhythm", "half-Leading", but only raised me more doubts.
Follow an example below to illustrate the case better:
*{
box-sizing:border-box;
margin:0;
padding:0;
font-size:16px;
}
body{
font-family: 'Roboto', sans-serif;
}
h1{
outline:1px solid red;
font-size:120px;
vertical-align:text-top;
line-height:normal;
}
h2{
outline:1px solid blue;
font-size:90px;
margin-top:10px;
}
h4{
font-size:16px;
line-height:normal;
outline:1px solid green;
/*line height = 24px;*/
/* 16 * 1.5 = 24px; */
}
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<h1>Font h1</h1>
<h2>Font h2</h2>
<h3>Font h3</h3>
<div class="wrapper">
<h4>Font h4</h4>
</div>
If you zeroed
padding
andmargin
, I believe that perhaps the only, and probably the best way would be toline-height
even, instead of usingline-height:normal
use it smaller than the source, for example: https://jsfiddle.net/leonardorodrigues/k6ebopvn/1/– Leonardo Rodrigues
@Leonardorodrigues and is there any standard to calculate this line-height? It was the only way I found it too, however in some fonts that one letter a little bigger than the other also can not align with the line-height
– haykou
maybe there is if you use a css framework (like Sass or Less). But from the basic css I don’t think
– Leonardo Rodrigues