Line-Height - Leaves No Vertically Centered Text

Asked

Viewed 1,053 times

2

I’m using the line-height to center a text vertically. But the text seems to me to have a small margin. Look at the image below, I selected the font to better see the spacing that’s making the difference in centering time.

You can fix that ?

Imagem

#userNome{
    width: 98%;
    margin: auto;
    margin-top: 50px;
    margin-bottom: 20px;
    line-height: 2;
    text-align: center;
    background-color: #FFF;
    border-radius: 5px;
    font-family: "Luckiest Guy";
    color: #AF3846;
    font-size: 26px;
    &.show{
        display: block;
    }
}

<div id="userNome">Olá, Diego Souza</div>

1 answer

1


The line-height does not serve to align the text vertically, who does it is the vertical-align (in your case, you want to vertical-align: middle;).

However, the line-height is necessary because the vertical-align align according to the line height and not the container in which the text is, ie you still need the line-height.

  • I’ve used the vertical-align with display:table and display:table-cell, but it didn’t work. It stayed the same way. I think the source is like this...

  • @Oeslei no need to specify unit of measure for line-height.

  • 1

    @You’re right. I corrected the answer!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.