console
function isOverflow(target){
let cHeight = target.clientHeight;
let sHeight = target.scrollHeight;
return sHeight >cHeight;
}
function initTip(){
const dom=document.querySelector(".panel");
const img=document.querySelector(".panel img");
const imgRect=img.getBoundingClientRect();
if(isOverflow(dom)){
dom.style.setProperty('padding-right',`${imgRect.width}px`);
img.style.setProperty('position','absolute');
img.style.setProperty('top','unset');
img.style.setProperty('bottom','0');
img.style.setProperty('right','0');
}
}
initTip();
<div class="panel">
今天天气真的123123123123213123
<img src="http://img01.yohoboys.com/contentimg/2018/11/22/13/0187be5a52edcdc999f749b9e24c7815fb.jpg" />
</div>
.panel{
position: relative;
width: 120px;
word-break: break-all;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
box-sizing: border-box;
outline: 1px solid lightpink;
background-color: lightgoldenrodyellow;
}
.panel img{
display:inline;
max-width: 20px;
position:relative;
top: 4px;
}