css盒子模型和尺寸

消除行内元素底部留白

行内盒模型


消除行内元素底部间隙:
原理:
middle对齐的是整个大盒子的行高中心位置往下偏移1/2字体的高度

<style>
    *{
        margin: 0;
        padding: 0;
    }
    html,body{
        height: 100%;
    }
.div1{
    display: inline-block;

    background: rebeccapurple;
}
.div2{
    display: inline-block;
    background: red;
    width: 150px;
    height: 150px;

}
</style>
<body>
<div class="div1" id="btn">
    <div class="div2"></div>
</div>
</body>

这里写图片描述
解决方法:

  1. .div1{line-height: 0; }
  2. .div1{font-size: 0;}
  3. .div2{ vertical-align: bottom;}
  4. .div2{ display:block}

猜你喜欢

转载自blog.csdn.net/zshsats/article/details/79946149
今日推荐