1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > css中white-space 属性:“pre” “pre-line” “pre-wrap” “nowrap”的区别

css中white-space 属性:“pre” “pre-line” “pre-wrap” “nowrap”的区别

时间:2018-10-12 15:36:48

相关推荐

css中white-space 属性:“pre”  “pre-line”  “pre-wrap” “nowrap”的区别

在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 ipsumdolor 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: normalis 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 hasbr

效果

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-wrapis very similar topreThe 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 preservedline break 1 – 6xtra 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.

效果

/@tohbansoon/differences-between-pre-pre-line-pre-wrap-and-no-wrap-in-css-1fe4b0f72699

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。