css - 关于table里面元素有display:inline-block的一些疑惑
天蓬老师
天蓬老师 2017-04-17 11:37:32
0
2
560
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body{font-size:14px;}
        .block{width:100%;background-color:red;}
        .a{display: table;width:100%;height:100%;}
        .b{display: table-cell;vertical-align: middle;}
        .c{display:inline-block;background-color:yellow;width:100px;height:8px;}
    </style>
</head>
<body>
    <p class="block">
        <p class="a">
            <p class="b">
                <p class="c"></p>
            </p>
        </p>
    </p>
</body>
</html>

如上代码,有两个问题想请问一下:
1.当.c的height为0的时候,为什么.b会有14的高度?
2.当.c的height不为0的时候,为什么距底边有间隙?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
巴扎黑
  1. The reason for font-size, when the height of .c is 0, set the font-size of .b to 0

  2. Both inline and inline-block will have this problem. The possible reason is that these two attributes will parse the spaces before and after, or parse them into characters. The solution is to set the font-size of .b to 0. Or replace the inline-block attribute of .c with the block attribute

Peter_Zhu
.c{display:inline-block;background-color:yellow;width:100px;height:0;}

That’s right, when the height of c is 0, the height of b is 16, not 14 as you said?
Google Test

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template