inline-block容器的高度撑开位置

block的高度是从最上面撑开的

那么inline-block呢?

直接上代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
    #test {
        line-height: 0;
        font-size: 80px;
        background-color: gray;
    }
    #test span {
        display: inline-block;
        background-color: red;
        height: 1px;
        width: 150px;
    }
    #s1 {
        
    }
    #s2 {
        line-height: 1;
    }
</style>
</head>

<body>
<div style="height: 100px;"></div>
<div id="test">
    <span id="s0"></span>
    <span id="s1">33</span>
    <span id="s2">33</span>
</div>
</body>
</html>

看到没?3个inline-block的撑开位置是不一样的。

同时把他们的父元素撑开了。

把3个inline-block高度加高试试

#test span {
        display: inline-block;
        background-color: red;
        height: 10px;
        width: 150px;
    }

撑开方向也不一样。

把span换成button试一试

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
    #test {
        line-height: 0;
        font-size: 80px;
        background-color: gray;
    }
    #test button {
        //display: inline-block;
        line-height: 0;
        font-size: 80px;
        background-color: red;
        height: 1px;
        width: 150px;
    }
    #s1 {
        
    }
    #s2 {
        line-height: 1 !important;
    }
</style>
</head>

<body>
<div style="height: 100px;"></div>
<div id="test">
    <button id="s0"></button>
    <button id="s1">33</button>
    <button id="s2">33</button>
</div>
</body>
</html>

height是1的时候跟span差不多的表现

增加height之后:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
    #test {
        line-height: 0;
        font-size: 80px;
        background-color: gray;
    }
    #test button {
        //display: inline-block;
        line-height: 0;
        font-size: 80px;
        background-color: red;
        height: 30px;
        width: 150px;
    }
    #s1 {
        
    }
    #s2 {
        line-height: 1 !important;
    }
</style>
</head>

<body>
<div style="height: 100px;"></div>
<div id="test">
    <button id="s0"></button>
    <button id="s1">33</button>
    <button id="s2">33</button>
</div>
</body>
</html>

中间元素的撑开方向与span不一样了

转载于:https://www.cnblogs.com/chen8840/p/4997610.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值