css white-space 属性用于设置如何处理元素内的空白,例设置white-space: nowrap,则换行及行首尾空格全部被合并,文本不会换行,文本会在在同一行上继续,直到遇到 <br> 标签为止。

css white-space属性怎么用?
white-space 属性设置如何处理元素内的空白。
这个属性声明建立布局过程中如何处理元素中的空白符。
立即学习“前端免费学习笔记(深入)”;
语法:
white-space : normal | pre | nowrap | pre-wrap | pre-line ;
属性值:
normal:默认。空白会被浏览器忽略。
pre:空白会被浏览器保留。其行为方式类似 HTML 中的 <pre> 标签。
nowrap:文本不会换行,文本会在在同一行上继续,直到遇到 <br> 标签为止。
pre-wrap:保留空白符序列,但是正常地进行换行。
pre-line:合并空白符序列,但是保留换行符。
说明:值 pre-wrap 和 pre-line 是 CSS 2.1 中新增的。
注释:任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit"。
css white-space属性 示例
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<head>
<style type="text/css">
.box{
width: 500px;
border: 1px solid #000;
margin-bottom:10px ;
}
.p1 {
white-space: nowrap
}
</style>
</head>
<body>
<div class="box">
<p>
php中文网
php中文网
php中文网
php中文网
php中文网
php中文网
php中文网
php中文网
php中文网
</p>
</div>
<div class="box">
<p class="p1">
php中文网
php中文网
php中文网
php中文网
php中文网
php中文网
php中文网
php中文网
php中文网
</p>
</div>
</body>
</html>输出:

以上就是css white-space属性怎么用的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号