使用 CSS3 截断溢出文本

cssweb developmentfront end technology更新于 2025/11/27 14:36:17

要截断溢出文本,请使用 word-wrap 属性并将其设置为"break-word"。以下代码展示了如何使用 CSS3 截断溢出文本 −

示例

<!DOCTYPE html>
<html>
<head>
<style>
div {
   font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   border: 3px solid #3008c0;
}
div.one {
   width: 200px;
   word-wrap: normal;
}
div.two {
   width: 200px;
   word-wrap: break-word;
}
</style>
</head>
<body>
<h1>Div1</h1>
<div class="one">
Lorem ipsum dolor sitametconsecteturadipisicjhbjhgjingelit. Rerum, beatae.
</div>
<h1>Div2</h1>
<div class="two">
Lorem ipsum dolor sitametconsecteturadipisicjhbjhgjingelit. Rerum, beatae.
</div>
</body>
</html>

输出

上述代码将产生以下输出 −


相关文章


有用资源