文字溢出添加省略号







<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文字溢出添加省略号 http://www.ablanxue.com/</title>
<style type="text/css">
	.mutil-line-ellipsis {
		width: 400px;
		height: 50px;
		line-height: 25px;
		margin: 20px 20px 50px 300px;
		border: 1px solid #AAA;
		line-height: 25px;
		overflow: hidden;
	}
	/*相当于之前的prop*/
	.mutil-line-ellipsis:before {
		content: '';
		float: left;
		width: 5px;/*缩小宽度为5px,其余属性不变*/
		height: 50px;
	}
	/*相当于之前的main*/
	.mutil-line-ellipsis > :first-child {
		float: right;
		width: 100%;
		margin-left: -5px;/*让main元素左移5px,这样main元素在宽度上就完全占满了父元素;*/
		word-break: break-all;
	}
	/*相当于之前的realEnd*/
	.mutil-line-ellipsis:after {
		content: '...';
		box-sizing: content-box;
		float: right;
		position: relative;
		width: 50px;
		height: 25px;
		top: -25px; /*等于高度的负值,就是文字的行高*/
		left: 100%;
		/*而设置margin-left: -50px、padding-right: 5px则是为了让realend元素的盒模型的最终宽度计算为5px。*/
		margin-left: -50px;
		padding-right: 5px;
		font-size: 13px;
		text-align: right;
		background: linear-gradient(to right, rgba(255, 255, 255, 0), #ffffff 40px);
	}

</style>
</head>
<body>
    <div class="mutil-line-ellipsis">
		<div>
			巴基斯坦总理阿巴西6日结束为期两天的尼泊尔之行,他是尼泊尔新总理奥利上台后接待的第一位外国领导人。两人不仅就双边关系进行磋商。
		</div>
	</div>
</body>
</html>

猜你喜欢

转载自lijun0349-163-com.iteye.com/blog/2412472