Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
Why when i add font size to h2, it adds line height to h2?

if you inspect number 5 you will see that line height is like 5 px above the tip of the number.. How can i change that to be just at the tip of the number without setting the line-height to something with px?

desirable result enter image description here

html,body{
    margin: 0;
    padding: 0;
}
h1 {
    margin: 0;
}
h2 {
    margin: 0px;
    
}


body {
    background-image: url("team2.jpg");
    background-size: cover;
    font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
    font-size: 1.5em;
    text-align: center;
    margin:20px 0 0 0;
}

#count-el{
/* margin: 10px 0 0 0; */
    font-size: 4em;
    height:max-content;
    

}
<html lang="en">
<head>
    <link rel="stylesheet" href="index.css">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>javascrpit project1</title>
</head>
<body>
    <div><h1>People entered</h1>
    <h2 id="count-el">0</h2>
    </div>
    <script>
        document.getElementById("count-el").innerText = 5
    </script>
    
</body>
</html>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The CSS line-height property, if defined without a unit, will calculate its value based on the font-size value.

The default value of line-height is around 1.2 that means a text with font-size of 16px will have a line-height of 19.2px (16 × 1.2) by default, and if you increase the font-size to 20px, the line-height will automatically be changed to 24px (20 × 1.2).

Therefore, to achieve what you want to do, you can either explicitly set a value with unit that matches the font-size, or set it to 1 to mean no multiplication.

p {
  font-size: 20px;
  text-decoration: underline;
}

p.a {
  line-height: 1;
}

p.b {
  line-height: 20px;
}

p.c {
  line-height: 0.5;
}

p.d {
  line-height: 0;
}
<p>line-height: normal<br>lorem ipsum dolor sit amet</p>
<p class="a">line-height: 1<br>lorem ipsum dolor sit amet</p>
<p class="b">line-height: matching font-size<br>lorem ipsum dolor sit amet</p>

<br>
<em>You can even set a value less than 1 (without unit) to down-scale it:</em>
<br>

<p class="c">line-height: 0.5<br>lorem ipsum dolor sit amet</p>
<p class="d">line-height: 0<br>lorem ipsum dolor sit amet</p>

about 4 years ago · Juan Pablo Isaza Denunciar

0

It's not pretty but you can set margin-top to a negative fraction of an em e.g. margin-top: -0.3em;, as in this snippet:

html,body{
    margin: 0;
    padding: 0;
}
h1 {
    margin: 0;
}
h2 {
    margin-top: -0.3em;
    }


body {
    background-image: url("team2.jpg");
    background-size: cover;
    font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
    font-size: 1.5em;
    text-align: center;
    margin:20px 0 0 0;
}

#count-el{
/* margin: 10px 0 0 0; */
    font-size: 4em;
    height:max-content;
    

}
<html lang="en">
<head>
    <link rel="stylesheet" href="index.css">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>javascrpit project1</title>
</head>
<body>
    <div><h1>People entered</h1>
    <h2 id="count-el">0</h2>
    </div>
    <script>
        document.getElementById("count-el").innerText = 5
    </script>
    
</body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda