`

CSS之 white-space : pre

    博客分类:
  • css
阅读更多
在 github 的代码浏览页面,可以看到这样的 css 样式:
<td class="blob-code-inner">        
  <span class="pl-k">throw</span> 
  <span class="pl-k">new</span> 
  <span class="pl-en">Error</span>(
  <span class="pl-s">
     <span class="pl-pds">"</span>
     Chartbeat: Please specify an api key and host!
     <span class="pl-pds">"</span>
  </span>);
</td>

<style>
.blob-code-inner {
    overflow: visible;
    font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 12px;
    color: #333;
    word-wrap: normal;
    white-space: pre;
</style>



显示效果:
// 注意:前面是有多个空格缩进的。
    throw new Error("Chartbeat: Please specify an api key and host!");




重点:

多个空格缩进的效果是由: white-space: pre; 控制的。

——————————————————————————————————————————————————————————————

语法:


Definition and Usage
The white-space property specifies how white-space inside an element is handled.


Property Values

__Value__ __Description__
normal Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default
nowrap Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a BR tag is encountered
pre Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the PRE tag in HTML
pre-line Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks
pre-wrap Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks






REF: http://www.w3schools.com/cssref/pr_text_white-space.asp







-


分享到:
评论

相关推荐

    英文强制换行css 使用css强制英文单词断行代码

    在做企业站的英文版的时候,英文单词由于剩下的空间不足,导致整个单词都换行,造成单词之间的空隙太大。如下图: 使用css属性word-break:break-all;...overflow:hidden 隐藏 white-space:normal 默认 pre 换行

    用CSS控制标题字数

    white-space:nowrap; course:hand; margin:0 auto;} HTML---------------------- 非常多的字数你能控制得了不可能的骗你是小狗&lt;/div&gt; ---------------------------------------------------------------------...

    CSS属性 - white-space 空白属性使用说明

    CSS 属性 - white-space 空白属性使用说明 白白空属性是 CSS 中一个重要的属性,它用于控制 HTML 元素中的空白处理。通过设置 white-space 属性,我们可以控制文本在元素中的换行、空格和制表符等空白符的处理方式...

    html pre标签使文本自动换行

    /*css-3*/ white-space:-moz-pre-wrap;/*Mozilla,since1999*/ white-space:-pre-wrap;/*Opera4-6*/ white-space:-o-pre-wrap;/*Opera7*/ word-wrap:break-word;/*InternetExplorer5.5+*/ }  该CSS方案可让pre标签...

    让pre标签自动换行示例代码

    pre 元素可定义预格式化的文本。被包围在 pre 元素中的文本通常会保留空格和换行符。而文本也会呈现为等宽字体。 &lt;pre&gt; 标签的一个常见... /* css3.0 */ white-space:-moz-pre-wrap; /* Firefox */ white-space:-pre-w

    三星9305收索

    white-space:nowrap;overflow:hidden}.bdsug .bdsug-direct p img{width:16px;height:16px;margin:7px 6px 9px 0;vertical-align:middle}.bdsug .bdsug-direct p span{margin-left:8px}.bdsug .bdsug-direct p i{...

    超出部分自动换行兼容多浏览器

    复制代码代码如下: &lt;style type=”text/css”&gt;... /* IE */ white-space: -moz-pre-wrap; /* Mozilla */ white-space: -hp-pre-wrap; /* HP printers */ white-space: -o-pre-wrap; /* Opera 7 */ whi

    CSS强制中英文换行与不换行 强制英文换行示例

    white-space:pre-wrap; 只对中文起作用,强制换行 4. white-space:nowrap; 强制不换行,都起作用 5. white-space:nowrap; overflow:hidden; text-overflow:ellipsis;不换行,超出部分隐藏且以省略号形式出现(部分...

    css是如何实现在页面文字不换行、自动换行、强制换行的方法

    white-space:nowrap; } 自动换行 div{ word-wrap: break-word; word-break: normal; } 强制英文单词断行 div{ word-break:break-all; } CSS设置不转行: overflow:hidden 隐藏 white-space:normal 默认 pre 换行和...

    CSS控制文字换行、裁剪

    关于换行、裁剪的一些CSS属性 word-wrap: normal | break-word normal 正常换行,内容可以撑破容器,例如长单词或者长数字的情况break-word 以单词...white-space: normal || pre || nowrap || pre-line || pre-wrap ||

    如何让pre和textarea等HTML元素去掉滚动条自动换行自适应文本内容高度

    即保留空格和换行符。... pre去掉滚动条 pre显示文本内容时是不会自动换行的,此时可以添加一些CSS来解决: &lt;pre&gt;ourjs this is very very very very very very very very very very very ... white-space: pre-wrap; pa

    mobile-first-approach-blogr-landing-page:前端管理员“ blogr-landing-page”提出的解决方案挑战

    移动第一方法毛发着陆页 前端管理员“ blogr-landing-page”提出的解决方案挑战 ...这是的解决方案。 前端导师挑战可帮助您构建现实的项目,从而提高您的编码技能。... white-space : pre-line; } //

    单元格内文本显示超过单元格宽度的快速解决办法

    解决办法: 在css中设置 white-space:normal; white-space:(1)normal : 默认 。空白会被浏览器忽略。  (2) pre : 换行和其他空白字符都将受到保护   (3) nowrap : 强制在同一行内显示所有文本,直到...

    sciter-sdk-4.4.4.3.zip

    Fixes: [css] layout optimization on runtime state and attribute changes; [a11y] various fixes; , CTRL+CLICK fix. [layout] white-space: pre-wrap; + TABs fix.

    z-blog SyntaxHighlighter 长代码无法换行解决办法(jquery)

    由于我的博客主要是代码分享,很多贴的代码,都很长。很多时候我都是手动给他换行...body .syntaxhighlighter .line{ white-space: pre-wrap !important;} .syntaxhighlighter{width:100%!important;margin:.3em 0 .3e

    百度地图开发文档

    white-space:-moz-pre-wrap;word-wrap:break-word} &lt;/style&gt; [removed][removed] &lt;/head&gt; &lt;body&gt; &lt;!--百度地图容器--&gt; ;margin:auto auto;" id="dituContent"&gt; &lt;/body&gt; [removed] ...

    网页中换行符的处理

    white-space 属性值有多种,包括 `nowrap`、`pre`、`pre-wrap`、`pre-line` 等。其中,`pre-wrap` 属性值正是我们所需要的:保留空白符,保留换行符,允许自动换行。 在实际应用中,我们可以将容器元素设置为 `{...

    CSS文本如何折行介绍

    pre-wrap 保留空白符序列,但是正常地进行换行。 pre-line 合并空白符序列,但是保留换行符。 inherit 规定应该从父元素继承 white-space 属性的值。 word-wrap:设置或检索当当前行超过指定容器的边界时是否断开...

    基于javascript的JSON格式页面展示美化方法

    {"name": "monkey","age": "24","height": 164.0} 如果想让以上json字符串在页面上展示的比较易读,即变成下面的style: ...white-space: pre; font-family: monospace; } &lt;/style&gt;  //script中是jav

    CSS 网页内容换行控制

    复制代码代码如下:语法: white-space : normal | pre | nowrap 取值: normal: 默认值。默认处理方式。文本自动处理换行。假如抵达容器边界内容会转到下一行 pre: 换行和其他空白字符都将受到保护。这个值需要IE...

Global site tag (gtag.js) - Google Analytics