Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent automatic line breaks in a <code> tag

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

Ugly line breaks!

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:

Single line

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

like image 338
Christian Engel Avatar asked May 08 '13 16:05

Christian Engel


Video Answer


1 Answers

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;

The problem was fixed.

like image 88
Christian Engel Avatar answered Sep 20 '22 04:09

Christian Engel