在css中white-space属性用来控制容器的文本中带有空白符、制表符、换行符等的显示,取值有:

  • normal:默认,忽略文本中所有的空白、换行符;只有文本存在 <br> 或文本达到框的约束时,文本才会换行
  • nowrap:和normal类似,忽略文本中所有的空白、换行符;遇到框的宽度约束时不会自动换行,文本只有在有 br 时才会换行
  • pre:保留文本中的空白、换行符;遇到框的宽度约束时不会自动换行,文本存在 <br> 或文本中有换行符时,文本才会换行
  • pre-wrap:和pre类似,保留文本中的空白、换行符;文本存在 <br> 或文本中有换行符时,或者遇到框的宽度约束时,文本都才会换行
  • pre-line:会略文本中的空白符;文本存在 <br> 或文本中有换行符时,或者遇到框的宽度约束时,文本都才会换行

示例:

.container {background-color: lightgreen;width: 300px;
}
.normal {white-space: normal;
}
.no-wrap {white-space: nowrap;
}
.pre {white-space: pre;
}
.pre-line {white-space: pre-line;
}
.pre-wrap {white-space: pre-wrap;
}

html模板:

<div class="container">Lorem         ipsum      dolor sit amet consectetur adipisicing elit.Unde velit       ullam iste labore earum.Nam    ea exercitationem <br> aspernatur <br> ipsum
</div>

1、white-space: normal

white-spaces: normal is the default value. All the source line break, extra white space/tab is collapsed. The text will only break into new line when there is <br> or if the text hit the constraint of the box.

效果:

2、white-space: nowrap

All the extra spacing/line break is collapsed.
Do not automatically break into new line when hit the width constraint of the box. Text will only break into new line when it has br

效果

3、white-space: pre

Sequences of white space are preserved. Lines are only broken at newline characters in the source and at <br> elements.

The text do not break into new line even when it hit the width constraint of the box. It will only break into new line if the source has new line or when it has <br>

效果

 4、white-space: pre-wrap

Sequences of white space are preserved. Lines are broken at newline characters, at <br>, and as necessary to fill line boxes.

pre-wrap is very similar to pre The only differences is the text will automatically break into a new line when it hit the width constraint of the box.

效果

5、white-space: pre-line

Sequences of white space are collapsed. Lines are broken at newline characters, at <br>, and as necessary to fill line boxes.

Source line break is preserved line break 1 – 6 xtra spacing is collapsed into single spacing. Text will automatically break into new line when hit the width constraint of the box , it has<br> and the source has new line.

效果

https://medium.com/@tohbansoon/differences-between-pre-pre-line-pre-wrap-and-no-wrap-in-css-1fe4b0f72699

css中white-space 属性:“pre”, “pre-line”, “pre-wrap” “nowrap”的区别相关推荐

  1. stm32中c语言换行符error——expect a declaration warning——“\“followed by white space is not a line splic

    标题 stm32中c语言换行符error--expect a declaration warning--""followed by white space is not a lin ...

  2. css text top,text-align属性(css中文本对齐属性)

    text-align属性 设置h1.h2.h3元素的文本对齐方法: h1{text-align:center} h2{text-align:left} h3{text-align:right} 亲自试 ...

  3. CSS中的resize属性

    CSS | 调整属性 (CSS | resize Property) Starting note: 开始说明: We deal with various elements regularly whil ...

  4. html text align属性,CSS中的text-align属性怎么用

    CSS的text-align属性可用于设置文本的位置,接下来的这篇文章将给大家介绍关于CSS中的text-align属性的用法,下面我们来看具体的内容. 我们先来看一段简单的代码 在此处显示文字 效果 ...

  5. CSS中Position定位属性的使用

    文章目录 CSS中定位属性的使用 position:absolute position:relative position:fixed position:sticky position:static ...

  6. html页边距为负值,css中的padding属性可以为负值吗?css中padding属性的详解

    关于css盒模型中的内边距padding属性的详细介绍,还有新手常犯的一个错误,内边距padding属性真的能写入负值.这个答案在文章的最后,现在就让我们一起来看这篇文章吧 首先我们介绍的是第一个问题 ...

  7. 【CSS】【position】css中的position属性

    css中的position属性用于设置元素位置的确定方式,它有以下几种取值: static:默认定位方式,子元素在父容器中挨个摆放 absolute:绝对定位,元素不占据父容器空间,相当于文档body ...

  8. html scale属性,CSS中的zoom属性和scale属性的用法及区别

    CSS中的zoom属性和scale属性的用法及区别 CSS中的zoom属性和scale属性的用法及区别是什么呢?以下是小编整理的相关内容,欢迎阅读学习! zoom 属性 语法: zoom:normal ...

  9. c语言中边框所占两列一行,css中的border-collapse属性如何设置表格边框线?(代码示例)...

    css中的border-collapse属性如何设置表格边框线?本篇文章就给大家介绍css中的border-collapse属性是什么? border-collapse属性设置表格边框线的方法.有一定 ...

  10. css中文本指什么,CSS中的文本属性

    本文总结一下CSS中关于文字的相关属性,最后给出实例. CSS基础文字属性 文字的基础属性主要包括:字体.颜色和文本.除去颜色color的属性外,字体和文本的相关属性可以权威参考: CSS 文本属性( ...

最新文章

  1. 0428(字典,列表,循环)
  2. 为什么有时候 php 没有写闭合标签结束符?
  3. Linux之软连接和硬链接
  4. mysql安装运行(centos)
  5. python判断文件或文件夹是否存在
  6. 离散分布的分布函数_数据分析|概率分布
  7. ASP页面中文乱码,已解决!!
  8. 如何区分网线是几类的_5类、6类网线双绞线如何区分又怎么样使用?
  9. PS27种图层混合模式
  10. 友盟用户反馈(官方文档学习而来)
  11. python和selenium爬虫,网页表格下载自动化脚本
  12. iterm配置alias
  13. 那些曾经大名鼎鼎的黑客,现在怎么样了?(第一集)
  14. Win10安装Docker和k8s
  15. Lighthouse performance scoring
  16. 18级的谷歌卫星地图纹理如何匹配到15级的高程
  17. 【Java】自定义异常
  18. UT8 编码引发的血案
  19. 图解 DDD 建模六个问题与六个步骤
  20. 基于MATLAB GUI的环境温湿度检测界面设计

热门文章

  1. 模拟cmos集成电路(8)
  2. zigzag算法详解
  3. 【cartographer_ros】一 : ros系统下的快速安装
  4. AMCL代码详解(七)amcl中的kd-Tree
  5. 基于stm32单片机的模拟IIC时序(附源码)
  6. 安卓美化——添加下拉菜单图片或下拉菜单透明
  7. Dubbox框架使用手册
  8. 英伟达发布全新GPU:采用图灵架构 支持光线追踪
  9. 英伟达或推出没有光线追踪的新款图灵架构GPU,这里有几个猜想...
  10. docker中调试失败