Align text vertically

I have the following HTML / CSS code in which a line of text is displayed in a green box with a dark green outline. Unfortunately, the text is shown closer to the top of the window. I would like it to be in the vertical middle. What do I need to change to get this effect?

Thanks PaulH

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title></title>   
    <style type="text/css">
    .foo
    {
        outline: 1px solid #98BF21;

        color: #333333;
        background-color: #EEFFCC;

        height: 27px;

        font-size: 15px;
        font-family: "Lucida Console","courier new";

        vertical-align: middle;

        margin: 1px 0px 0px;
        padding: 0px 5px;

        overflow: auto;
        display: inline-block;
    }
</style>
</head>
<body>
    <span class="foo">Lorem ipsum dolor sit amet, consectetur adipisicing elit</span>
</body>
</html>
+3
source share
2 answers

See here .

In your case, if your text is only one line, method 2 works. Just replace heightwith line-height.

+2
source
<div style="display:table-cell; vertical-align:middle;">
Stuff showing in the Vertical Middle of this Div
</div>
0
source

Source: https://habr.com/ru/post/1796071/


All Articles