深入理解CSS中的行高

2018-05-30  本文已影响166人  小杺

基线、底线、顶线

1.png

行距、行高

2.gif

内容区

3.gif

行内框

4.gif

行框

5.gif

元素对行高的影响

6.png

对于inline-block 和 inline 的嵌套问题

需要了解的基本概念

术语

结论:

介绍几个概念叫做行内对齐规则自基准选取规则

纯粹inline嵌套

对于行框内部存在一套隐式的对齐网格,我将这套对齐网格称之为行框网格(对于行内框,也有同样的隐式的对齐网格,称之为行内框网格

混合嵌套(inline-block,inline)

混合嵌套依然遵循行内对齐规则,只是对于inline-block自基准选取的时候和inline的选取规则不一样。

例子

  <style>
    .align-left {
        height: 50px;
        width: 50px;
        display: inline-block;
        word-wrap:break-word;
    }

    .align-left:nth-child(odd) {
        background-color: darkorange;
    }

    .align-left:nth-child(even) {
        background-color: aqua;
    }
</style>

<div class="container">
    <div class="align-left"></div>
    <div class="align-left"></div>
    <div class="align-left"></div>
    <div class="align-left">12sdfjsdf</div>
    <div class="align-left"></div>
    <span>sdfe</span>
</div>
<div>
    <div class="align-left"></div>
    <div class="align-left"></div>
    <div class="align-left"></div>
    <div class="align-left"></div>
    <div class="align-left"></div>
</div>
inlineBlock.png
<div style="border:1px solid black;">
    <span>hello world Well I wonder<span style="display:inline-block; border:1px solid red; width:100px;"> could it be When I was dreaming about you baby You were dreaming of me Call me crazy Call me blind To still be suffering is stupid after all </span>of this time Did I lose my love to someone better And does she <span>love you like I do I do,</span> you know I really really do Well hey So much I need to say</span>
    <span>hello node</span>
    <span>hello nice</span>
</div>
inlineBlock2.png
<div style="border:1px solid black; margin-top:50px;">
    <span style="vertical-align: top;">hello world Well I wonder<span style="border:1px solid red;"> could it be When I was dreaming about you baby You were dreaming of me Call me crazy Call me blind To still be suffering is stupid after all </span>of this time Did I lose my love to someone better And does she <span style="font-size: 2em;">love you like I do I do,</span> you know I really really do Well hey So much I need to say</span>
    <span>hello node</span>
    <span>hello nice</span>
</div>
inlineBlock3.png
上一篇下一篇

猜你喜欢

热点阅读