防止在& lt; code& gt;中自动换行标签 [英] Prevent automatic line breaks in a <code> tag

查看:45
本文介绍了防止在& lt; code& gt;中自动换行标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html code 标记,包裹在具有固定宽度的 pre 标记中,并且得到了难看的自动换行符:

I have a html code tag, wrapped in in a pre tag with fixed width and am getting ugly automatic line breaks:

我想要实现的是,文本不会在空格上自动打断,但是当我在 code 元素中添加 white-space:nowrap 时,整个内容折叠成一行,因此所有\ n和\ r字符也将被忽略:

What I want to achieve is, that the text is NOT automatically broken on spaces, but when I add a white-space: nowrap to the code element, the whole thing collapses to a single line, so all \n and \r characters are ignored as well:

有人知道如何防止自动换行,但要保留预期的换行吗?

Does anyone have an idea how to prevent automatic line breaks, but keep the intended line breaks?

推荐答案

问题是由Twitter引导程序引起的.无论出于何种原因,他们在代码标签中添加了以下样式:

The problem was caused by twitter bootstrap. For whatever reason, they added the following styles to the code tag:

white-space:pre;
white-space:pre-wrap;
word-break:break-all;
word-wrap:break-word;

通过以下方式覆盖样式:

By overwriting the styles with:

white-space: pre;
word-break: normal;
word-wrap: normal;

问题已解决.

这篇关于防止在& lt; code& gt;中自动换行标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆