`

Wrapping Text Inside Pre Tags

    博客分类:
  • web
阅读更多
http://www.longren.org/2006/09/27/wrapping-text-inside-pre-tags/

sometimes display little snippets of code on this site. For example, here, here, and here. To do this, I use the Code Markup wordpress plugin.

If you’re using Firefox, you may notice the long lines in my Digg Integrator fix post. It’s not really a problem for me having those really long lines in Firefox. Why? Because Firefox still displays my sidebar correctly. Internet Explorer is a totally different story though. When there’s long lines like that, my sidebar will appear at the very bottom of the page in IE.

The long lines are caused by use of the pre html tag. The pre tag preserves spaces and line breaks in a chunk of text. Perfect for displaying snippets of code. However, some lines of code are quite long and will run off the page. This is exactly why my sidebar was getting pushed to the bottom of the page in IE.

So, I set out looking for a method to wrap text contained within pre tags. Google found exactly what I was looking for. Wrapping text inside pre tags is quite easy, all that’s required is a simple addition to your css:

pre {
 white-space: pre-wrap;       /* css-3 */
 white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
 white-space: -pre-wrap;      /* Opera 4-6 */
 white-space: -o-pre-wrap;    /* Opera 7 */
 word-wrap: break-word;       /* Internet Explorer 5.5+ */
}


Quite simple. After adding that CSS, the text in pre tags still doesn’t wrap in Firefox, but I don’t care because Firefox displays the rest of my page as it should. Now, when you view a page in IE with a long line, the text is wrapped and my sidebar content appears at the top of the page instead of the bottom.

For consistency sake, let’s make these long lines wrap in Firefox too. This is extremely simple. It only requires adding a few characters to the CSS shown above. For text wrapping in Firefox, use this CSS:
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 */
 word-wrap: break-word;       /* Internet Explorer 5.5+ */
}



Notice the only difference between the first and second examples is the addition of “!important” to the third line in example 2. After adding that little bit, your text between your pre tags should wrap well in basically every browser that’s currently in use.



If you can’t seem to get the css above to work, give the css below a shot. I just set a width on the pre tag. When the width is set to 100%, you’ll get a horizontal scrollbar when viewing in IE7. That’s why I’ve set the width to 99%. The code will display just fine in IE6, IE6, and FireFox when width is set to 99%. I have not tested Opera. Try this updated CSS if you’re having issues with the original CSS from above.
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 */
 word-wrap: break-word;       /* Internet Explorer 5.5+ */
 width: 99%;
}




Markku Laine posted some css in a comment that seems to work better than the original css I posted. It works in IE, Safari, and FireFox. Try using Markku’s css below if the previous examples don’t work for you.
pre {
 overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
 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 */
 /* width: 99%; */
 word-wrap: break-word; /* Internet Explorer 5.5+ */
}

Certification exams from cisco like 350-001 and 640-802, also from the other vendors like Microsoft having similar exams 70-290 and 70-291 along with lesser known vendors Vmware VCP-310 can help you brush up your skills on networking as well as web skills
分享到:
评论

相关推荐

    fdct_wrapping.zip_MATLAB 曲波去噪_fdct_wrapping函数_彩色图像去噪_曲波去噪matlab_

    本压缩包"fdct_wrapping.zip"包含了一个名为"fdct_wrapping"的MATLAB函数,专门用于实现曲波去噪,特别是针对彩色图像。 首先,让我们深入理解曲波去噪的基本原理。曲波变换(Wavelet Transform)是一种多分辨率...

    Android代码-wrapping-viewpager

    WrappingViewPager ViewPager replacement with dynamic height support and smooth animations ... compile 'com.github.iffa:wrapping-viewpager:1.10' } Quick start Integrating the library takes less than f

    Dynamic Time Wrapping的源代码

    动态时间规整(Dynamic Time Warping,简称DTW)是一种在序列数据中寻找最佳匹配路径的算法,尤其在语音识别、时间序列分析等领域有广泛应用。本压缩包包含DTW算法的源代码及相关辅助文件,以下是关于DTW算法及其源...

    fdct_wrapping_demo_disp.rar_DEMO_curvelet_fdct_曲波_曲波系数

    fdct_wrapping_dispcoef - 返回一个包含所有图像曲波系数的图象

    英文原版-CSS Text Styling Your Words 1st Edition

    text wrapping, and the direction of text flow.This book is an excerpt from the upcoming fourth edition of CSS: The Definitive Guide. When you purchase either the print or the ebook edition of CSS ...

    wrapping-up.zip

    在"wrapping-up.zip"这个压缩包中,包含了完成的剑铲示例游戏的源代码和资源,这为我们提供了一个绝佳的学习平台,以实践的方式理解闭环系统在游戏中的应用。 首先,闭环系统的核心在于“反馈”,即系统能够感知并...

    back_up_wrapping_10_25.zip_back_面 OPENGL

    这个"back_up_wrapping_10_25.zip_back_面 OPENGL"文件可能包含了一个关于如何利用OpenGL进行3D图形编程的项目或者教程,特别是关于背面剔除(back-face culling)和纹理坐标包裹(wrapping)的技术。 首先,让我们...

    fdct_wrapping_matlab_Demo.zip_DEMO_curvelet_curvelet-pcnn_fdct_w

    《fdct_wrapping_matlab_Demo.zip_DEMO_curvelet_curvelet-pcnn_fdct_w》是一个包含Matlab演示的压缩包,重点展示了曲线let(Curvelet)变换在图像处理中的应用,尤其是与频率域离散余弦变换(FDCT)和曲线let-PCNN...

    Swift-API-Wrapping:带闭包的基本 API 包装类(支持 Alamofire)

    Swift-API-Wrapping 带闭包的基本 API 包装类(支持 Alamofire) 例子 APIWrapping.sharedManager.get("get", params: nil, success: { (responseObject) -> Void in println(responseObject) // Wrap JSON result ...

    wrapping-viewpager视图替换

    【wrapping-viewpager视图替换】是一个针对Android平台的自定义视图组件,它扩展了标准的`ViewPager`,以解决在某些特定场景下`ViewPager`功能的局限性。`ViewPager`是Android SDK中用于展示可滑动页面的常用控件,...

    wrap_相位缠绕_缠绕相位_

    在图像处理和计算机图形学领域,相位缠绕(Phase Wrapping)是一种处理相位数据的技术,主要用于增强图像的形变结果。这个概念通常应用于如光学相干断层扫描(Optical Coherence Tomography, OCT)、声学成像、地震...

    <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.

    fdct_wrapping.rar_波变换_matlab_

    3. **Wedge Wrapping(楔包装)**:这是Curvelet变换的一种优化策略,它通过特殊的几何布局(类似楔形)来排列Curvelet系数,从而提高计算效率和数据存储的有效性。这种包装技术使得计算和重构过程更快,对于大规模...

    strings-wrapping:用全角字符和ANSI代码包装字符串

    字符串::包装 用全角字符和ANSI代码包装字符串。... strings = Strings :: Wrapping . new strings . wrap ( "It is not down on any map; true places never are." , 20 ) # =&gt; "It is not down on\nany map; true p

    RMI wrapping-开源

    标题提到的"RMI wrapping-开源"项目,是一个专门针对非远程对象的RMI自动包装的Java库。这个库的目的是简化RMI的使用,特别是对于那些原本不是为远程调用设计的对象。它可能通过动态代理或者其他技术,将非远程对象...

    pandas-wrapping-0.0.3.tar.gz

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、...

    In situ wrapping of the cathode material in lithium-sulfur batteries

    锂硫电池是一种极有潜力的下一代高密度储能设备,因为其成本低廉的硫正极具有高的理论比容量,达到了1672mAh/g。然而,锂硫电池在实际应用中存在一个固有的多硫化物穿梭效应问题,这严重限制了它们的应用。...

    vtk-wrapping-example:在Python中包装基于VTK的自定义类的示例

    在Python中包装自定义VTK类的独立测试/示例。 两者都可以一劳永逸地弄清楚这一点,并在将来有一些参考。 基于VTK 6.2(和OpenGL2模块) CMake命令是从不同的来源和示例中拼凑而成的,例如 来自vtk用户列表的帮助

Global site tag (gtag.js) - Google Analytics