CSS3 white-space

刺骨的言语ヽ痛彻心扉 2022-05-15 15:06 184阅读 0赞

在这里插入图片描述























































white-space 空格 换行 <br> 容器边界换行
normal 合并 忽略 换行 换行
nowrap 合并 忽略 换行 忽略
pre 保留 换行 换行 忽略
pre-wrap 保留 换行 换行 换行
pre-line 合并 换行 换行 换行
inherit 换行
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf8">
  5. <style>
  6. .container {
  7. width: 15em;
  8. height: 10em;
  9. border: 1px solid #bbb;
  10. background-color: #eee;
  11. margin: 10em;
  12. display: inline-block;
  13. }
  14. </style>
  15. <script>
  16. const str = `Let's test the property about " white-space " , whitch can use six values
  17. (1)normal
  18. (2)pre
  19. (3)nowrap<br>
  20. (4)pre-wrap<br/>
  21. (5)pre-line
  22. (6)inherit`;
  23. const whiteSpaces = ["normal", "pre", "nowrap", "pre-wrap", "pre-line"];
  24. window.onload = ()=>{
  25. for(value of whiteSpaces) {
  26. const div = document.createElement("div");
  27. div.setAttribute("class", "container");
  28. div.style.whiteSpace = value;
  29. /*
  30. innerHtml 写入字符串,<br>等标签字符会被转为它实际的意义而不会显示出来
  31. innerText 把字符串全部当成文本,包括<br>等标签也全部转为文本显示出来
  32. createTextNode 等同于innerText,区别是innerText是一次性赋值,createTextNode之后还可以多次插入
  33. */
  34. const node = document.createTextNode(value + "<br>" + str);
  35. div.appendChild(node);
  36. //div.innerHTML = value + "<br>" + str;
  37. //div.innerText = value + "<br>" + str;
  38. document.body.appendChild(div);
  39. }
  40. }
  41. </script>
  42. </head>
  43. <body>
  44. </body>
  45. </html>

发表评论

表情:
评论列表 (有 0 条评论,184人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CSS3

    CSS3是什么?         CSS3是CSS2的升级版本,它是用于控制网页的样式和布局,3只是版本号,目前主流的Chrome、safari、firefox、opera、

    相关 css3

    HTML5中增加了很多新标签,也改变一些标签的用法。标签更注重语义上的关联性。 新的结构元素有:header,footer,hgroup,article,section,as

    相关 CSS3

    CSS3 一、CSS3新增选择器 1.属性选择器 2.结构伪类选择器 3.伪元素选择器 二、CSS3盒模型 三、