开发者社区> 问答> 正文

line-height font-size

各位大神小弟有一事请教:
代码如下:

<style type="text/css">
    .oDiv{
        width:50%;
        font-size: 144px;
        line-height:1em;
        margin:0 auto;
        border:2px solid #beceed;
    }
    .oDiv span{
        font: 14px/1.2em '微软雅黑';
        display: inline-block;
        vertical-align: middle;
    }
</style>
</head>
<body>
    <div class="oDiv">
        <span>却未曾感觉你在心口的鼻息<br/>我已经相信有些人我永远不</span>
    </div>
</body>
执行结果中span并未垂直居中
但是将css代码改为:
.oDiv{
    width:50%;
    line-height:144px;
    margin:0 auto;
    border:2px solid #beceed;
}
.oDiv span{
    font: 14px/1.2em '微软雅黑';
    display: inline-block;
    vertical-align: middle;
}
就垂直居中了,这是为什么?恳请各位大神指教!

展开
收起
杨冬芳 2016-06-08 14:53:16 1926 0
1 条回答
写回答
取消 提交回答
  • IT从业

    vertical-align:middle 并不是垂直居中,而是把span的行框中点跟.oDiv的基线上1/2x处对齐,你oDiv的字体那么大,1/2x处当然很不明显居中了。
    w3c的规定是这样的 https://www.w3.org/TR/CSS2/visudet.html#line-height

    Align the vertical midpoint of the box with the baseline of the parent box plus half the x-height of the parent.

    screenshot

    2019-07-17 19:31:59
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Transforming the data center 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载