css教程css怎么实现内容超出隐藏效果

 所属分类:web前端开发

 浏览:121次-  评论: 0次-  更新时间:2022-10-18
描述:更多教程资料进入php教程获得。 css实现内容超出隐藏效果的方法是,给文本内容添加text-overflow属性,例如【text-overflow:ellipsis】。te...
更多教程资料进入php教程获得。

css实现内容超出隐藏效果的方法是,给文本内容添加text-overflow属性,例如【text-overflow:ellipsis】。text-overflow属性指定当文本溢出包含它的元素应该发生什么。

前端(vue)入门到精通课程:进入学习
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API调试工具:点击使用

本文操作环境:windows10系统、css 3、thinkpad t480电脑。

css为我们提供了一个很适合的元素text-overflow,这个属性指定当文本溢出包含它的元素,应该发生什么。

语法:

text-overflow: clip|ellipsis|string;
登录后复制

属性值:

  • clip 修剪文本。

  • ellipsis 显示省略符号来代表被修剪的文本。

  • string 使用给定的字符串来代表被修剪的文本。

举个例子:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<style> 
div.test
{
	white-space:nowrap; 
	width:12em; 
	overflow:hidden; 
	border:1px solid #000000;
}
</style>
</head>
<body>

<p>以下 div 容器内的文本无法完全显示,可以看到它被裁剪了。</p>
<p>div 使用 &quot;text-overflow:ellipsis&quot;:</p>

<div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box</div>
<p>div 使用 &quot;text-overflow:clip&quot;:</p>
<div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div>
<p>div 使用自定义字符串 &quot;text-overflow: &gt;&gt;&quot;(只在 Firefox 浏览器下有效):</p>
<div class="test" style="text-overflow:'>>';">This is some long text that will not fit in the box</div>
</body>
</html>
登录后复制

展示效果:

09718b20987e44577b191ba264b68ef.png

相关视频分享:css视频教程

以上就是css怎么实现内容超出隐藏效果的详细内容,更多请关注zzsucai.com其它相关文章!

 标签: css,内容,
积分说明:注册即送10金币,每日签到可获得更多金币,成为VIP会员可免金币下载! 充值积分充值会员更多说明»

讨论这个素材(0)回答他人问题或分享使用心得奖励金币

〒_〒 居然一个评论都没有……

表情  文明上网,理性发言!