Whether a single line of text judges whether it overflows

The method of judging whether a line of text is overflowing is often used to see more

 

.text_wrapper{
    height: 20px;
    line-height: 20px;
    width: 150px;
    border: 1px salmon solid;
    font-size: 16px;
    color: #1c1c1c;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

 <div style="height: 200px;width: 200px;display: table-cell;vertical-align: middle;">
        <div class="text_wrapper">Big brother-in-law Fang Jianai's color release</div>
    </div >

 let ele = document.querySelector(".text_wrapper");
    console.info(ele.innerHTML)
    console.info(ele.scrollWidth);
    console.info(ele.offsetWidth);
    let scrollWidth = ele.scrollWidth;
    let offsetWidth = ele.offsetWidth;
    if(scrollWidth>offsetWidth){
        alert("文本溢出")
    }

Guess you like

Origin blog.csdn.net/cuiyuchen111/article/details/98968722