`

Wrap the line in pre

 
阅读更多

Problem:

The <pre> tag of html is used to keep the format of the content as it is inputted. So, if the content is a long line of text with no line break, then it will displayed as one line and can be out of the container's scope. Even if we've already applied " word-wrap: break-word;" on the <div> outside the <pre>

This is surely ugly on the page. We expect a feature like notepad's auto line feed, so that when it is too long, it will wrap the line automatically.

 

Solution:

Add " word-wrap: break-word;" to the outside <div>

Apply the following css to <pre> tag.

 

pre {
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
}

 

Now it looks like this:

 

Try it with jsfiddle

 

  • 大小: 5.5 KB
  • 大小: 24.1 KB
分享到:
评论

相关推荐

    <pre> Line Wrapper-crx插件

    语言:English (United States) ... tags:pre { white-space: pre-wrap; }This takes effect immediately on all active pages.I've published the (very short) source code under the Apache 2.0 license.

    微软内部资料-SQL性能优化3

    In our example, if one transaction (T1) holds an exclusive lock at the table level, and another transaction (T2) holds an exclusive lock at the row level, each of the transactions believe they have ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Header Files The #define Guard Header File Dependencies Inline Functions The -inl.h Files Function Parameter Ordering Names and Order of Includes Scoping Namespaces Nested Classes Nonmember, Static ...

    Bochs - The cross platform IA-32 (x86) emulator

    In addition to the default Bochs method using the CTRL key and the middle mouse button there are now the choices: - CTRL+F10 (like DOSBox) - CTRL+ALT (like QEMU) - F12 (replaces win32 'legacyF12'...

    ak2新版内核AKAIO1.5

    For those unfamiliar with all the additions the AKBBS (now AIO) software has in comparison to the stock firmware, here's a sampling of the bigger changes: * Cheat Improvements - R4/XML Cheat File ...

    cuteEditor6.0

    支持图片的文字环绕 &lt;br/&gt;Locate the image you want to wrap text around, and click any justify button in the toolbar. The image will float to the desired direction. Text will be ...

    ARM® Compiler v5.06 for µVision® armasm User Guide

    1.4 Directives that can be omitted in pass 2 of the assembler 2 Overview of the ARM Architecture 2.1 About the ARM architecture 2.2 ARM, Thumb, and ThumbEE instruction sets 2.3 Changing between ARM, ...

    CSS控制文字换行、裁剪

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

    CSS文本如何折行介绍

    pre-line 合并空白符序列,但是保留换行符。 inherit 规定应该从父元素继承 white-space 属性的值。 word-wrap:设置或检索当当前行超过指定容器的边界时是否断开转行。 normal 控制连续文本换行。 break-w

    让多个div在同一行显示的样式及html代码

    word-wrap:break-word; } 复制代码代码如下: &lt;pre name=”code” class=”css”&gt;&lt;!–width指定每个div占据的宽度–&gt;&lt;/pre&gt;.custom_div{height: 23px;width: 50px;line-height: 23px;float: left;} &lt;pre&gt;&lt;/pre&gt; ...

    UG6.0快捷键大全

    POPUP_MESSAGE Edits parameter values of the selected feature in the current model state. ACTIONS STANDARD BUTTON UG_EDIT_FEATURE_DIMENSION LABEL Feature Dimension... MESSAGE Edits the selected ...

    Printed Circuits Handbook

    12.7 Manufacturability in the Shop / 12.23 Part 4 Engineering and Design Chapter 13. Physical Characteristics of the PCB 13.3 13.1 Classes of PCB Designs / 13.3 13.2 Types of PCBs or Packages for ...

    CSS中的空白效果属性使用小结

    white-spacewhite-space用来设置浏览器对“空白”的处理,所谓的空白指的是你在编辑器...pre-wrap:保留所有空白,但是正常地进行换行(chrome,FF,IE8+,Opera),在IE6和IE7下等同于normalpre-line:合并空白符序

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

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

    三星9305收索

    left:0}#pad-version{line-height:40px}.s_ipt_wr.bg,.s_btn_wr.bg,#su.bg{background-image:none}.s_btn_wr{width:auto;height:auto;border-bottom:1px solid transparent;*border-bottom:0}.s_btn{width:100px;...

    HTML 网页设计

    .wrap{ width:95%; margin:0 auto; } /***** Header ****/ .header{ border-top:5px solid #111; } .logo{ text-align:center; margin:10px 0; } .menu { text-align:center } .menu li a{ font-size:0.8em; ...

    windows dos环境下直接运行linux命令集合

    addr2line.exe gzip.exe run.exe alternatives.exe head.exe runcon.exe ar.exe hostid.exe rxvt.exe arch.exe hostname.exe scp.exe as.exe hpftodit.exe sdiff.exe ascii.exe i686-pc-cygwin-gcc-3.4.4.exe sed....

Global site tag (gtag.js) - Google Analytics