简体   繁体   English

在垂直中间对齐文本

[英]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. 我有以下HTML / CSS代码,其中一行文本显示在带有深绿色轮廓的绿色框中。 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 谢谢,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. 在您的情况下,如果您的文本只有一行,方法2工作。 Just replace height by line-height . 只需更换heightline-height

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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