绝对定位超出父元素后,未设置宽度,文字换行问题

2018-10-11  本文已影响0人  葱头来了

问题

父元素设置了宽高,子元素为文本,绝对定位,代码如下:

<div class="icon_list_item_imgview">
   <span class="icon_list_item_imgview_tag">免试</span>
</div>

.icon_list_item_imgview {
    width: 36px;
    height: 36px;
    margin: 0 auto 7px;
    position: relative;
}
.icon_list_item_imgview_tag {
    display: block;
    height: 14px;
    line-height: 14px;
    font-size: 10px;
    position: absolute;
    left: 23px;
    bottom: 27px;
    color: black;
    padding: 0 5px;
    text-align: center;
}

left: 0时显示如下

C9D075B8-5EDF-4262-843F-5D5041A14D57.jpeg
left:23px时显示如下
WX20181011-201041.png

主要原因: 未设置.icon_list_item_imgview_tag的宽度,导致元素移到父元素外后自动换行导致的
解决办法: 增加css属性 white-space: nowrap,解决问题。

1539260192334.jpg
上一篇 下一篇

猜你喜欢

热点阅读