Responsive pre tag - html

I simply want to show terminal output on a Webpage. Atm I'm using a pre tag to do that with pre { white-space: pre-wrap; } as you can see upon http://irc.dabase.com/.
My problem is that when I rotate my iPhone6 IOS device, it often doesn't reformat properly. Why is this? Can you offer some good CSS rules to make this use case of showing terminal output on a Webpage better?

pre {
white-space: pre-wrap;
word-wrap: break-word;
text-align: justify;
}
Here are the rules you need explained step by step:
Select all pre elements (set this to pre#yourID or pre.yourClass to select a specific pre)
pre {
Allow pre to wrap at word breaks and line breaks. Unlike pre-line, pre-wrap will not modify your terminal output at all. pre-line will modify your terminal output by condensing whitespace into one whitespace which could make finding exact phrases difficult or mess with whitespace column formatting! See here
white-space: pre-wrap;
Make sure that words that go past the end of the element break off instead of being hidden (like links for examples)
word-wrap: break-word;
This part is optional Justify the text so that it fully fills the line. Spaces become wider but their number is not increased.
text-align: justify;
}
Optionally, this rule can be fit into a media-query so that it only applies in the mobile version. But I believe there is no harm in applying this rule to all screen sizes by simply omitting a media-query.
In the event that the wider version of your iphone makes your pre rule stop working, you should check to see if there isn't already a media-query in place that is applying a rule to the pre when the screen reaches a certain size.
You can also try intentionally creating a media-query for the wider version, which may re-initialize the styles if there is some kind of bug going on.
For example:
Include rule that applies to smallest possible version
Rule A:
pre {
white-space: pre-wrap;
word-wrap: break-word;
text-align: justify;
}
Then in addition to rule A include another rule to re-initialize styles at landscape orientation
Rule B:
#media all and (orientation:landscape)
pre {
white-space: pre-wrap;
word-wrap: break-word;
text-align: justify;
}
}

You can try this to achieve -
pre {
white-space: pre-line;
word-wrap: break-word;
}

pre {
white-space: pre-line;
word-wrap: break-word;
text-align: justify;
}
You Can Try It Once

This worked nicely for me when I had pre tag inside of a table and code below made pre tag stay responsive to the table column width. Credits to: https://techstacker.com/responsive-pre-tags-css/
pre {
white-space: pre-wrap;
word-break: break-all;
}

Related

Wrapping <pre> to a fixed width such that each line is the same length in characters

I'm attempting to wrap this long <pre> so that it forms a rectangle (rather than having the "jagged" endings I'm getting). I've set white-space to pre-wrap and word-break to break-all like other StackOverflow posts have suggested, but it seems like the browser is still applying some heuristics on where to break the line.
I cannot break the <pre> into rows a-priori because both the length of the content, as well as the width of the <pre> may be dynamic.
pre {
width: 300px;
white-space: pre-wrap;
word-break: break-all;
}
<pre>ER..............................3......|..f1.f1.fSfQ.W....R..|.........K...R.A..U1.0....r...U.u....t.f.....B....1.ZQ....[...#P..?Q..SRP..|...f....D.....f#.....f.>#|..xpu....{.D|.....isolinux.bin missing or corrupt...f`f1.f...{f...{fRfP.Sj.j...f.6.{.........6.{....A......{...d.fa....Operating system load error...^....>b.....<.u........................</pre>
What I have:
What I want to achieve:
line-break: anywhere; works well in Chrome (Canary) and Firefox, but not Edge. If the content contains spaces, you should probably use white-space:break-spaces rather than pre-wrap as well.
pre {
width: 300px;
white-space: break-spaces;
line-break: anywhere;
}
<pre>ER..............................3......|..f1.f1.fSfQ.W....R..|.........K...R.A..U1.0....r...U.u....t.f.....B....1.ZQ....[...#P..?Q..SRP..|...f....D.....f#.....f.>#|..xpu....{.D|.....isolinux.bin missing or corrupt...f`f1.f...{f...{fRfP.Sj.j...f.6.{.........6.{....A......{...d.fa....Operating system load error...^....>b.....<.u........................</pre>

Large words showing wrong in phone view

I have a text with one large word and it's broke the phone view.
Please see the picture attached.
picture here
apply the word-wrap CSS property on your content
* { word-wrap: break-word }
you'll better off if you are a bit more specific with your selector instead of '*' like:
p { word-wrap: break-word }
this will allow the long word(s) to be broken and wrapped onto the next line.
You can use this, just apply the CSS to the text container.
.word-wrap {
word-wrap: break-word; /* IE 5.5-7 */
white-space: -moz-pre-wrap; /* Firefox 1.0-2.0 */
white-space: pre-wrap; /* current browsers */
}

Force all lines HTML content (with embedded element) to fill width of container

I have a piece of HTML content such as:
<span class="wrappable"><i>(03/10/2016) Author Name</i> LongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreakLongContentWithoutLineBreak</span>
The "wrappable" css class is defined as:
.wrappable
{
overflow-wrap: break-word !important;
word-wrap: break-word !important;
white-space: normal !important;
display: inline !important;
}
Please refer to https://jsfiddle.net/dn9tt26e/ run the fiddle.
At least in Firefox version 45.0.1, this produces an output that breaks on the first line without the line filling the width of its container. For pure text content, there is no such issue, but as soon as I add an embedded HTML element, seems the issue appears.
How do I ensure all lines (excepts perhaps the last) fill the full width of the container without breaking prematurely?
Some pictures of what I see in my browser:
Suggested solution using break-word:all https://jsfiddle.net/4bu8ctt4/ in Firefox:
Local page on my machine in Firefox:
Local page in IE 11 (this one does not wrap the second line at all)
You have basically 2 words combined with break-word, which means it'll put any long word in new line. Try with word-break: break-all;
https://jsfiddle.net/4bu8ctt4/
Im sorry if i misunderstood you, but maybe this helps?
add property to your class
word-wrap: break-word;
like this
.wrappable
{
overflow-wrap: break-word !important;
word-wrap: break-word !important;
white-space: normal !important;
display: inline !important;
word-wrap: break-word;
}
source:
http://www.w3schools.com/cssref/css3_pr_word-wrap.asp

CSS override white-space:nowrap on a website

A website that I use on a regular basis does this. This causes way to much stuff to be on a single line and it goes off the screen. It needs to do word wrapping but what see below prevents it.
div.dbThreadDetailTreeRowCellItem {
white-space: nowrap;
}
https://stackoverflow.com/a/1258512/985898
I don't want to have to open firebird and fix it every time I go to the website. Is there hopefully an easy way to fix this with your css files? I am using firefox.
https://superuser.com/a/295806/93715
Firefox User Profile Folder --> Chrome -- > userChrome.css
I added this to my userChrome.css file. What do I need to add to my css file?
.break-word {
word-wrap: break-word;
}
-moz-hyphens: auto;
p
{
white-space:normal;
}
.u_nowrap {
white-space: normal !important;
}
pre { white-space: pre-wrap !important; }
Is there also a way to fix this issue in Chrome?
It doesn't look like any of your css rules apply to the container you said is causing the problem.
Try adding this line:
div.dbThreadDetailTreeRowCellItem{ word-wrap: break-word !important; white-space: normal !important; }

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:
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?
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.
I hope this might help you. Demo
.content pre
{
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
white-space: pre-wrap;
word-wrap: break-word; /* Internet Explorer 5.5+ */
}