css文字超出长度用省略号代替,鼠标悬停并以悬浮框显示

本文介绍使用CSS实现超长字段自动用省略号表示的方法,适用于所有浏览器,包括实现字段超长时显示省略号及鼠标悬停显示完整内容的技术细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文字在超出长度时,如何实现用省略号代替?

用CSS实现超长字段用省略号表示的方法:所有浏览器兼容! 
html代码如下:

<div style="width:150px;overflow:hidden; white-space:nowrap; text-overflow:ellipsis">用CSS实现超长字段被省略的简单方法</div>

鼠标移入移出显示和隐藏

html:

<div class="relaDiv"> 
    <div style="width:120px;overflow:hidden; white-space:nowrap; 
         text-overflow:ellipsis; color:black" class="mouseOver">
        <span class="tit f_bold">外呼原因:</span>${order.oper_remark }
    </div>
    <div class="absoDiv"> 
        <div class="absoDivHead">外呼原因</div>
        <div class="absoDivContent"> 
            <span class="tit f_bold">外呼类型:</span>${order.outcall_type_c }<br/>
            <span class="tit f_bold">外呼原因:</span>${order.oper_remark }
            <c:if test="${empty order.oper_remark }">无原因</c:if>
	   </div>
	</div>
</div> 

css:

<style>

.relaDiv {
    position: relative;
    height: 30px;
    line-height: 30px;
}
.absoDivHead {
    border-bottom: 1px solid #d5d5d5;
    background: #dbdbdb;
    line-height: 20px;
    text-align: left;
    margin: 0px;
    padding-left: 5px;
    font-weight: bold;
}
.absoDivContent {
    padding: 5px;
}
.absoDiv {
    position: absolute;
    display: none;
    line-height: 20px;
    width: 350px;
    top: 24px;
    left: 0px;
    height: auto;
    border: 1px solid #d5d5d5;
    background: #fff;
    z-index: 100;
    background: #FCFCE4;
    text-align: left;
}
</style>

js:

function showOrg(item){
    var row = $(item).closest("tr");
    var orgDiv = $(row).find(".absoDiv");
    var orgContent = $(row).find(".absoDivContent");
	$(orgDiv).attr("style","display:block");

}
	
function hideOrg(item){
	var row = $(item).closest("tr");
	$(row).find(".absoDiv").attr("style","display:none");
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值