简体   繁体   中英

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>

See here .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM