English 中文(简体)
中文本
原标题:middle text in a div
  • 时间:2011-06-23 23:38:51
  •  标签:
  • html
  • css

为什么这一例子中的案文:。 http://jsfiddle.net/7EYZe/。 不是在垂直中心?

我怎么能够讨论案文?

EDIT:
Now I have two or more lines of text: http://jsfiddle.net/7EYZe/12/

How can I display this properly?

最佳回答

The following css will central text in a div by using patter rather than high:

 .centerText
    {
        padding: 90px 0;
        font-size: 18px;
        border:solid 1px #000;
    }
问题回答

这对<代码>垂直-align的使用不正确。 它不了解纵向统一的目标是什么。

这里是一个动态的无表格解决办法:。 http://jsfiddle.net/imoda/7EYZe/14/

<style type="text/css">
    div {
        height:200px;    
        width:200px;
        border:solid 1px black;
    }

    .aligner {
        height: 100%;
        width: 0;
        display: inline-block;
        vertical-align: middle;
    }

    .align {
        display: inline-block;
        vertical-align: middle;
    }
</style>

<div>
    <span class="aligner"></span>
    <span class="align">blabla</span>
</div>

添加文字字体:中心;显示:桌子;在盒子中集中。

div {
    height:200px;    
    width:200px;
    border:solid 1px black;
    text-align: center;
    vertical-align:middle;
    display: table-cell;
}

零四在环绕的任何地方都垂直地连接起来。 这不影响内面的东西。 使其规模缩小,事实上消除了阴道,将其置于更大范围内。

事实是,纵向关系主要是为了明确表层人物的行为。 虽然名称表明任何内容都应与中间内容一致,但只是没有。

http://phrogz.net/cs/vertical-align/index.html” rel=“nofollow”

使用<条码>在线-八:200px,例如

div {
  border:solid 1px black;
  height:200px; 
  line-height:200px;  
  width:200px;
}

另外,在您的榜样中,你赢得了t needvertical-align:middle。 这意味着,<代码>div将纵向调整至括号>。 这并不意味着案文将纵向统一。

This is way too much of a pain to do with a div. Use a table cell instead:
html: <table><tr><td>My Text</td></tr></table>
css: td { vertical-align: middle; }





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!