当前位置:Gxlcms > css > csswhite-space属性怎么用

csswhite-space属性怎么用

时间:2021-07-01 10:21:17 帮助过:102人阅读

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

css white-space属性怎么用?

white-space 属性设置如何处理元素内的空白。

这个属性声明建立布局过程中如何处理元素中的空白符。

语法:

  1. 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属性 示例

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. </head>
  6. <head>
  7. <style type="text/css">
  8. .box{
  9. width: 500px;
  10. border: 1px solid #000;
  11. margin-bottom:10px ;
  12. }
  13. .p1 {
  14. white-space: nowrap
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div class="box">
  20. <p>
  21. Gxl网
  22. Gxl网
  23. Gxl网
  24. Gxl网
  25. Gxl网
  26. Gxl网
  27. Gxl网
  28. Gxl网
  29. Gxl网
  30. </p>
  31. </div>
  32. <div class="box">
  33. <p class="p1">
  34. Gxl网
  35. Gxl网
  36. Gxl网
  37. Gxl网
  38. Gxl网
  39. Gxl网
  40. Gxl网
  41. Gxl网
  42. Gxl网
  43. </p>
  44. </div>
  45. </body>
  46. </html>

输出:

1.jpg

以上就是css white-space属性怎么用的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行