How to Soft-wrap code on GitHub website on the on the - css

When I'm looking at a text file on GitHub.com, how can I make it wrap the lines instead of having horizontal scroll?
In the GitHub website editor, I can choose the option "Soft Wrap" from a top-right drop down, but there is no such drop down, nor any option anywhere on the page that I can find, to also wrap lines when just viewing code.
I've tried to write user stylesheets to customise the appearance, but manually setting the width of the <td> that the line of code is in or the <table> that the code and line numbers are in doesn't actually change the width of that element, and setting different overflow values here doesn't change the behaviour either.

This is because the td.blob-code table cells containing code lines in GitHub viewer have the CSS rule white-space: pre, which forcefully prevents breaking at white space no matter what (it also overrides width etc. properties)
table.pre td {
white-space: pre;
}
table.normal td {
white-space: normal;
}
<code>white-space: pre;</code>
<table class="pre">
<tbody>
<tr>
<td>1</td>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla posuere nisi at enim vehicula faucibus. Sed lobortis malesuada finibus. Nunc bibendum id erat nec aliquet. Aenean convallis gravida nisi dapibus facilisis. Proin gravida consectetur porta. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sodales odio maximus orci vulputate, non aliquet felis ornare. Nunc convallis orci eget urna laoreet, sit amet suscipit arcu interdum. Nam vel ante tellus.</td>
</tr>
<tr>
<td>2</td>
<td>Curabitur sed volutpat tortor, molestie faucibus justo. Praesent at massa vitae felis interdum ultricies ac at ante. Curabitur lobortis, urna nec sodales mattis, nibh velit rhoncus mauris, in sagittis odio eros ut velit. Mauris a cursus sem. Integer id varius nisi. Nullam posuere molestie blandit. Donec dapibus elementum ex sit amet hendrerit.</td>
</tr>
</tbody>
</table>
<code>white-space: normal;</code>
<table class="normal">
<tbody>
<tr>
<td>1</td>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla posuere nisi at enim vehicula faucibus. Sed lobortis malesuada finibus. Nunc bibendum id erat nec aliquet. Aenean convallis gravida nisi dapibus facilisis. Proin gravida consectetur porta. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sodales odio maximus orci vulputate, non aliquet felis ornare. Nunc convallis orci eget urna laoreet, sit amet suscipit arcu interdum. Nam vel ante tellus.</td>
</tr>
<tr>
<td>2</td>
<td>Curabitur sed volutpat tortor, molestie faucibus justo. Praesent at massa vitae felis interdum ultricies ac at ante. Curabitur lobortis, urna nec sodales mattis, nibh velit rhoncus mauris, in sagittis odio eros ut velit. Mauris a cursus sem. Integer id varius nisi. Nullam posuere molestie blandit. Donec dapibus elementum ex sit amet hendrerit.</td>
</tr>
</tbody>
</table>
To overwrite this via a user stylesheet and enable word-wrapping in GitHub, simply overwrite that rule on the <td>s:
#repo-content-turbo-frame .blob-code-content td.blob-code {
white-space: normal !important;
}

Related

How do I make a <pre> horizontally scroll and not overflow when inside a non-fixed table cell?

I have this:
<table>
<tbody>
<tr>
<td>
<pre style="overflow: scroll;">
(really long lines of text)
JSFiddle: https://jsfiddle.net/x7n8w02f/
In my scenario, I have these considerations:
The <table> cannot have table-layout: fixed (in my real-world page the <table> has width: 100% but in the JSFiddle it's width: 600px).
The width of the <td> varies.
No word-wrapping in the <pre> and whitespace must be preserved.
The <pre> needs to fill the width of the <td>.
The text within the <pre> must not overflow or overspill outside the visual bounds of the <pre> (which would be the same as the <td>, disregarding padding and margins), so tThe <pre> must scroll horizontally if its text is wider than the <td>.
However there doesn't seem to be any way to do this!
All solutions I've seen so far place a few limitations on the document and stylesheet:
Use table-layout: fixed on the <table>.
Set an absolute width on the <pre> with overflow: scroll (or overflow-x: scroll), e.g. width: 500px but not width: 100% (which doesn't work).
I've varied all of the white-space, word-wrap, overflow, and overflow-x CSS properties to no effect.
If I've understood the requirements correctly, you can put the pre element in as an absolute positioned box inside a relatively positioned td element. Like this.
table {
border: 1px outset #999;
width: 600px;
}
td, th {
border: 1px inset #999;
}
.pre-container {
position: relative;
}
pre {
border: 1px solid red;
overflow: auto;
position:absolute;
left:0;
right:0;
margin:0;
top:0;
bottom:0;
}
<table>
<tbody>
<tr>
<td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</td>
<td class="pre-container">
<pre>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nisl nisi, volutpat eget tempus vitae, iaculis non magna. Phasellus efficitur ante ipsum, eget posuere diam dapibus at. Sed vel leo sit amet sapien feugiat congue. Nunc lorem velit, bibendum eu dignissim eu, efficitur ultrices metus. Suspendisse accumsan dolor ut tortor maximus, et volutpat velit eleifend. Donec commodo malesuada auctor. Proin cursus euismod porttitor. Duis posuere id ex sollicitudin vestibulum. Sed nisi odio, imperdiet ac mollis sit amet, luctus id odio. Fusce laoreet libero non nunc ornare, ac pharetra mi rutrum. Quisque rhoncus vehicula lorem, sit amet consequat neque. Nullam sodales ligula ac orci tincidunt semper. In efficitur magna ut viverra eleifend.
Donec luctus purus nunc, id suscipit nisi dignissim quis. Vivamus vel ligula massa. Proin nec scelerisque ligula. Mauris tristique metus enim. Quisque blandit nunc at nunc maximus laoreet. Nunc nisl sapien, lacinia vitae risus vitae, rutrum interdum nibh. Nunc a sem sem. Ut leo lectus, tempus a sagittis eu, mattis eu orci. Pellentesque dignissim mi diam, et sollicitudin leo facilisis pretium. Ut et tempor dolor. Suspendisse laoreet odio elit, at ultricies justo pellentesque quis. Vestibulum et diam ac ipsum laoreet maximus ac eu elit. Integer et elementum urna.
Curabitur sagittis tortor eu justo laoreet, nec pharetra massa congue. Duis hendrerit venenatis diam, non suscipit arcu. Quisque aliquam pretium mauris, ac cursus risus eleifend nec. Nulla non sem ac mi auctor tempus in nec velit. In cursus vel ex nec pellentesque. Etiam consequat eget libero nec dictum. Vestibulum viverra neque vel urna semper vehicula. Praesent ac felis sollicitudin, convallis nisi vel, consequat lorem. Morbi eu elit at enim tempor maximus vel ut magna. Integer dignissim convallis consequat.
Fusce aliquam libero in sem volutpat rhoncus. Suspendisse vulputate interdum nibh non efficitur. Morbi massa dolor, egestas a sodales a, rhoncus quis turpis. Vivamus velit erat, rutrum vitae lectus sed, luctus vulputate augue. Aenean elementum tortor eros, eget hendrerit purus viverra eget. Praesent ultricies pulvinar gravida. Nullam pulvinar feugiat laoreet. Fusce sit amet est facilisis, mattis erat a, consectetur felis. Sed eleifend faucibus felis, eget auctor nunc egestas suscipit. Sed in lobortis mi. Phasellus aliquet elit at tristique ullamcorper. Nullam augue eros, ornare et nisl ac, tempor volutpat sem. Praesent in felis vehicula, imperdiet mi eget, laoreet diam.
Praesent at tellus diam. Fusce vulputate, ipsum non vulputate vehicula, elit sem viverra mi, eu suscipit arcu leo et mi. Curabitur nec dolor ultrices, bibendum eros hendrerit, gravida ex. Donec ac porttitor erat. Nullam gravida egestas mi, vel tristique ante suscipit nec. Nullam ut ante rhoncus nisi varius feugiat. Pellentesque aliquet tincidunt ante vitae sollicitudin.</pre>
</td>
</tr>
<tr>
<td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</td>
<td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</td>
</tr>
</tbody>
</table>

Implementing the html5 sticky style property with consistent behaviour

I am trying to use the html5 style property sticky in both the firefox and safari browsers but the behaviour is different when there is a table within the containing area.
Is there a way to style the table to allow the sticky element to display over the table in safari?
Here is a codepen demonstrating the behaviour.
Here is the css
.sticky {
position: -webkit-sticky;
position: -moz-sticky;
position: -o-sticky;
position: -ms-sticky;
position: sticky;
top: 10px;
z-index: 1;
display: inline-block;
width: 100%;
box-sizing: border-box;
}
And here is the html
<div>
<h2 class="sticky">This is just sticky</h2>
Massa id neque aliquam vestibulum morbi blandit cursus. Elit eget gravida cum sociis natoque penatibus. Adipiscing tristique risus nec feugiat in fermentum posuere urna. Aliquet sagittis id consectetur purus ut. Nisi vitae suscipit tellus mauris a. Suspendisse sed nisi lacus sed. Sed pulvinar proin gravida hendrerit lectus a. Mauris nunc congue nisi vitae. Mi bibendum neque egestas congue quisque egestas diam. Velit aliquet sagittis id consectetur purus ut. At varius vel pharetra vel turpis nunc eget lorem dolor. Erat velit scelerisque in dictum non. Gravida arcu ac tortor dignissim convallis. Suscipit adipiscing bibendum est ultricies integer quis auctor elit sed. Magna eget est lorem ipsum dolor. Aenean sed adipiscing diam donec adipiscing tristique risus nec feugiat.
<table class="table--ledger" border="1">
<tr>
<td>First Value</td>
<td>Second Value</td>
<td>Third Value</td>
<td>Fourth Value</td>
<td>Fifth Value</td>
<td>Sixth Value</td>
<td>Seventh Value</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>$2.75</td>
<td>$95.63</td>
<td>$62.10</td>
<td>$0.80</td>
<td>$72.79</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>$2.19</td>
<td>$61.54</td>
<td>$76.07</td>
<td>$29.41</td>
<td>$98.75</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
<td>$6.97</td>
<td>$59.19</td>
<td>$90.49</td>
<td>$20.93</td>
<td>$69.93</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>$3.11</td>
<td>$21.67</td>
<td>$71.98</td>
<td>$49.37</td>
<td>$71.13</td>
</tr>
<tr>
<td>5</td>
<td>5</td>
<td>$1.10</td>
<td>$95.75</td>
<td>$25.13</td>
<td>$33.41</td>
<td>$47.73</td>
</tr>
</table>
</div>
<h1 class="vertical-space-large">here is some more text...</h1>
<h1 class="vertical-space-large">and here is even more text...</h1>
<div data-lorem="p">
<span class="sticky"><h2>This is sticky as well</h2></span>
Massa id neque aliquam vestibulum morbi blandit cursus. Elit eget gravida cum sociis natoque penatibus. Adipiscing tristique risus nec feugiat in fermentum posuere urna. Aliquet sagittis id consectetur purus ut. Nisi vitae suscipit tellus mauris a. Suspendisse sed nisi lacus sed. Sed pulvinar proin gravida hendrerit lectus a. Mauris nunc congue nisi vitae. Mi bibendum neque egestas congue quisque egestas diam. Velit aliquet sagittis id consectetur purus ut. At varius vel pharetra vel turpis nunc eget lorem dolor. Erat velit scelerisque in dictum non. Gravida arcu ac tortor dignissim convallis. Suscipit adipiscing bibendum est ultricies integer quis auctor elit sed. Magna eget est lorem ipsum dolor. Aenean sed adipiscing diam donec adipiscing tristique risus nec feugiat. Magna fermentum iaculis eu non diam phasellus vestibulum lorem sed. Ultrices in iaculis nunc sed augue lacus viverra. Consequat interdum varius sit amet mattis. Mattis pellentesque id nibh tortor id.
Aliquam eleifend mi in nulla posuere. Fringilla est ullamcorper eget nulla facilisi etiam dignissim. Quis lectus nulla at volutpat. Morbi enim nunc faucibus a pellentesque sit amet porttitor. Interdum posuere lorem ipsum dolor sit amet consectetur adipiscing elit. A iaculis at erat pellentesque. Faucibus in ornare quam viverra orci sagittis eu volutpat. Quam lacus suspendisse faucibus interdum posuere lorem ipsum dolor sit. Ultricies leo integer malesuada nunc vel. Erat nam at lectus urna duis convallis convallis. Ante in nibh mauris cursus mattis molestie a iaculis. Sagittis nisl rhoncus mattis rhoncus urna neque. Dolor sit amet consectetur adipiscing elit ut aliquam. Sed felis eget velit aliquet sagittis. Eget arcu dictum varius duis. Neque convallis a cras semper auctor neque vitae tempus quam.
Turpis cursus in hac habitasse platea dictumst quisque. Velit laoreet id donec ultrices. Consequat mauris nunc congue nisi vitae suscipit tellus mauris a. Vitae et leo duis ut. Diam in arcu cursus euismod quis. Aenean euismod elementum nisi quis eleifend quam adipiscing vitae. Diam volutpat commodo sed egestas egestas fringilla phasellus faucibus scelerisque. Sapien pellentesque habitant morbi tristique. Nisi scelerisque eu ultrices vitae. Nunc eget lorem dolor sed viverra ipsum nunc aliquet. Sapien et ligula ullamcorper malesuada proin libero. Bibendum ut tristique et egestas. Id diam vel quam elementum pulvinar etiam non quam.
</div>
<h1 class="vertical-space-large">here is some more text...</h1>
<h1 class="vertical-space-large">and here is even more text...</h1>
The reason for the differences between the inconsistant behaviour, of the display of the html5 sticky style property, is how each of the browsers implement 'sticky' when there is a display property present or not.
Adding a
display: inline-block;
or
display: block;
as appropriate - it may affect your layout - will mitigate this.
See this codepen for a demonstraion.

Text Overlapping over Image

The structure of my image and paragraphs is as follows:
<p class="All-Book-Text">Maecenas iaculis, ipsum at tempor placerat, orci ligula aliquam enim, sit amet sagittis turpis enim sit amet lorem. Praesent dapibus pretium felis, et tempus nibh posuere a.</p>
<div class="_idGenObjectLayout-3">
<div id="_idContainer062" class="ObjExpOpt-Images">
<img class="_idGenObjectAttribute-1" src="image/animal.png" alt="" />
</div>
</div>
<p class="All-Book-Text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam imperdiet elementum ex, a porttitor arcu vulputate vitae. Mauris ac finibus nisi. Etiam at tellus vitae quam pretium eleifend. Donec at dictum nisi, id condimentum dui. Donec in tortor ipsum. Etiam sit amet turpis vulputate, maximus erat in, lacinia leo. Cras placerat lobortis fermentum. Phasellus vulputate libero et pellentesque mattis. Aenean tristique ante egestas nibh aliquet, a sagittis sem aliquam. Aenean sit amet diam elementum, cursus arcu non, vehicula lorem. Sed vitae ante id augue consectetur euismod. Suspendisse ac metus ut tortor mollis semper eget eu mi. Vivamus eleifend leo at felis bibendum rutrum. Proin condimentum consectetur velit, at tristique elit accumsan vel.</p>
When the page renders, the text of the lower paragraph overlaps over the image. How can I prevent this and make sure that the distance between the image and the parapgraph is 5 px and no overlap occurs whatsoever. Thanks!
Here's a live demo with my problem http://jsfiddle.net/zvnjnxnf/
Everything looks ok here: JsFiddle
p {display: inline}
img {display: block}
first, you should remove all the style for All-Book-Text and _idGenObjectLayout-3
then add the following css :
._idGenObjectLayout-3{
padding : 5px;
}

Label doesn't work between lines if line-height greater 1

The label tag doesn't work between lines if line-height of the paragraph is greater than 1em.
<p style="line-height: 2em;"><input type="checkbox" id="xx" />
<label for="xx">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat quis magna sed varius. Suspendisse scelerisque cursus nunc et pulvinar. In nec metus dolor. Fusce blandit leo quis nulla scelerisque dignissim. Mauris fermentum diam sed metus venenatis pellentesque. Maecenas tellus lacus, condimentum in nibh et, ornare pharetra felis. Fusce mollis libero nisl, eu sodales mauris sagittis id.
</label></p>
See here: jsfiddle
Is there a way to prevent that?
I'm not sure how valid it is and in which versions of HTML, but you can wrap the whole paragraph with the label.
<label for="xx">
<p style="line-height: 2em;">
<input type="checkbox" id="xx" /> ...
</p>
</label>
Demo: http://jsfiddle.net/2nFdq/1/
If you don't need to use label for="" syntax you can do the following.
HTML:
<p style="line-height: 2em;">
<label>
<input type="checkbox" id="xx" />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat quis magna sed varius. Suspendisse scelerisque cursus nunc et pulvinar. In nec metus dolor. Fusce blandit leo quis nulla scelerisque dignissim. Mauris fermentum diam sed metus venenatis pellentesque. Maecenas tellus lacus, condimentum in nibh et, ornare pharetra felis. Fusce mollis libero nisl, eu sodales mauris sagittis id. Maecenas semper nisi et augue imperdiet rutrum. Vivamus at viverra metus! Quisque eleifend cursus massa, sed facilisis diam ultrices ac. Nulla facilisi. Donec auctor adipiscing tellus id interdum. Nullam sodales libero sed lacus consectetur sollicitudin. Maecenas lacinia risus in lectus tincidunt, quis luctus turpis sollicitudin.
</label>
</p>
CSS:
label{
display:block;
}
See the fiddle.
Functionality is similar if you only add the CSS style but then you need to style the checkbox to align it nicely with the label text. (The label text occupies it's own block. In this solution it shares a block space with the checkbox.)
Update
Here's an alternative solution using CSS and label for="" syntax (Please use CSS. Inline styling is hard to maintain.):
<p><input type="checkbox" id="xx" />
<label for="xx">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat quis magna sed varius. Suspendisse scelerisque cursus nunc et pulvinar. In nec metus dolor. Fusce blandit leo quis nulla scelerisque dignissim. Mauris fermentum diam sed metus venenatis pellentesque. Maecenas tellus lacus, condimentum in nibh et, ornare pharetra felis. Fusce mollis libero nisl, eu sodales mauris sagittis id. Maecenas semper nisi et augue imperdiet rutrum. Vivamus at viverra metus! Quisque eleifend cursus massa, sed facilisis diam ultrices ac. Nulla facilisi. Donec auctor adipiscing tellus id interdum. Nullam sodales libero sed lacus consectetur sollicitudin. Maecenas lacinia risus in lectus tincidunt, quis luctus turpis sollicitudin.
</label>
</p>
CSS:
label{
line-height:2em;
display:block;
}
input[type="checkbox"]{
float:left;
position:relative;
margin:.5em .5em 0 0;
}
See the fiddle.

Make paragraph text fill container

I've seen a property that allow you to fill the entire width of a container with text, ala magazine style. It simply increases the space between words to accommodate for the additional space.
What is this property?
You're thinking of text-align: justify.
div {
text-align: justify;
}
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nec nisl ipsum, at ullamcorper justo. Vivamus ac dui lorem. Aliquam nec diam urna, in semper augue. Etiam commodo dui velit. Vestibulum in nibh nulla, a feugiat justo. Proin accumsan, tellus et condimentum laoreet, lacus lorem consequat nisi, ac fermentum velit eros at metus. Aliquam lacinia mollis felis, vel pretium nulla condimentum consectetur. Quisque in mattis nibh. Nunc adipiscing tincidunt elit, vitae pellentesque felis molestie ac. Fusce vestibulum dui in nibh gravida ut placerat ligula porta. Ut sem lectus, condimentum nec tincidunt a, imperdiet vitae risus.</div>

Resources