PaulH
PaulH

Reputation: 7863

aligning text in the vertical middle

I have the following HTML/CSS code in which a line of text is shown in a green box with a dark green outline. Unfortunately, the text is shown closer to the top of the box. I would like it to be in the vertical middle. What do I need to change to get that 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>

Upvotes: 3

Views: 403

Answers (2)

leonbloy
leonbloy

Reputation: 75976

See here.

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

Upvotes: 2

John K.
John K.

Reputation: 5474

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

Upvotes: 0

Related Questions