发布网友
共2个回答
热心网友
提供两个方案给你:1、在页面的脚本语言里面用类似于left的函数;2、找个js或jq代码来实现,css是需要很大的耐心去调整谦容性的,而且有一些bug是解决不了的;overflow:hidden;强制居中width:200px;white-space:nowrap;强制在同一行内显示所有文本,直到文本结束或者遭遇br对象text-overflow:ellipsis;这才是超出后用省略代替 下面给个例子给你<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title>text-overflow_CSS参考手册_web前端开发参考手册系列</title>
<meta name="author" content="Joy Du(飘零雾雨), dooyoe@gmail.com" />
<meta name="copyright" content="www.doyoe.com" />
<style>
.test li{margin-top:10px;}
.test .clip p{overflow:hidden;width:200px;white-space:nowrap;text-overflow:clip;}
.test .ellipsis p{overflow:hidden;width:200px;white-space:nowrap;text-overflow:ellipsis;}
</style>
</head>
<body>
<ul class="test">
<li class="clip">
<strong>clip: 直接将溢出的文字裁剪</strong>
<p>测试用文字测试用文字测试用文字测试用文字测试用文字测试用文字</p>
</li>
<li class="ellipsis">
<strong>ellipsis: 将溢出的文字显示省略标记(...)</strong>
<p>测试用文字测试用文字测试用文字测试用文字测试用文字测试用文字</p>
</li>
</ul>
</body>
</html>
热心网友
overflow:hidden; 内容超出宽度时隐藏超出部分的内容