css3怎么让字体不换行

来自:互联网
时间:2022-03-29
阅读:

CSS3怎么让字体不换行

在css中,可以使用white-space属性来强制文字不换行;通常我们使用white-space:nowrap来强制文本文字内容不换行,文本会在在同一行上显示,直到遇到 <br> 标签为止。

white-space属性设置或检索对象内文本显示方式。

语法:

white-space : normal | nowrap;

属性值:

  • normal:默认。空白会被浏览器忽略。

  • nowrap:文本不会换行,文本会在在同一行上继续,直到遇到 <br> 标签为止。

示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
div {
width: 120px;
height: 60px;
line-height: 20px;
border: 1px dashed #ccc;
margin: 10px;
}
.demo {
white-space: nowrap
}
</style>
</head>
<body>
<div>内容将会不被换行显示</div>
<div class="demo">内容将在一行内强制显示完整</div>
</body>
</html>

效果图:

css3怎么让字体不换行

返回顶部
顶部