CSS3 white-space

在这里插入图片描述

white-space空格换行<br>容器边界换行
normal合并忽略换行换行
nowrap合并忽略换行忽略
pre保留换行换行忽略
pre-wrap保留换行换行换行
pre-line合并换行换行换行
inherit换行
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<style>
.container {
	width: 15em;
	height: 10em;
	border: 1px solid #bbb;
	background-color: #eee;
	margin: 10em;
	display: inline-block;
}
</style>
<script>
const str = `Let's test the property about "     white-space     " , whitch can use six values
(1)normal
(2)pre
(3)nowrap<br>
(4)pre-wrap<br/>
(5)pre-line
(6)inherit`;
const whiteSpaces = ["normal", "pre", "nowrap", "pre-wrap", "pre-line"];

window.onload = ()=>{
	for(value of whiteSpaces) {
		const div = document.createElement("div");
		div.setAttribute("class", "container");
		div.style.whiteSpace = value;
		/*
		innerHtml		写入字符串,<br>等标签字符会被转为它实际的意义而不会显示出来
		innerText		把字符串全部当成文本,包括<br>等标签也全部转为文本显示出来
		createTextNode	等同于innerText,区别是innerText是一次性赋值,createTextNode之后还可以多次插入
		*/
		const node = document.createTextNode(value + "<br>" + str);
		div.appendChild(node);
		//div.innerHTML = value + "<br>" + str;
		//div.innerText = value + "<br>" + str;
		document.body.appendChild(div);
	}
}
</script>
</head>
<body>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值