span和img标签对齐

html代码

<li>

    <span class="left_item">在线</span>

    <img class="right_item item_img"  src="../../assets/admin/image/ztree_forbid.png" alt=""/>

</li>

相关css

.left_item {

    width: 30%;

    height: 100%;

    display: inline-block;

    box-sizing: border-box;

    vertical-align: middle;

}



.right_item {

    width: 40%;

    height: 100%;

    display: inline-block;

    box-sizing: border-box;

    vertical-align: middle;

}



.item_img{

    width: 40px;

    height: 40px;

}



li {

    padding: 5px 10px;

    width: 100%;

    vertical-align: middle;

    box-sizing: border-box;

    display: block;

}

效果图:

 

注意点:image和span都设置

vertical-align: middle;

image的高度和宽度不能用百分比,必须写死像素px

 

你可能感兴趣的:(span)