diff2html: Line Number Row is overflowing when it's wrapped inside a fixed height div.
Step -1: Before filling an issue check out troubleshooting section
Step 0: Describe your environment
- OS: Mac OS Mojave
- diff2html version: 3.4.3
- Using diff2html directly or using diff2html-ui helper: diff2html directly
- Extra flags: _
Step 1: Describe the problem:
When wrapping the HTML coming from diff2html.html in fixed-sized div line numbers column seems to be broken.
The below screenshot best describes the issue,

Steps to reproduce:
const diffHtml = diff2html.html(diffString, {
drawFileList: true,
matching: "lines",
outputFormat: 'side-by-side',
});
$content.html(diffHtml);
diff example:
===================================================================
--- backend-markdown
+++ frontend-markdown
@@ -3,11 +3,9 @@
<a href="https://github.com/jgm/commonmark.js">commonmark.js</a>, the<br>
JavaScript reference implementation.</p>
<ol>
<li>item one</li>
-<li>
-<p>item two</p>
-<ul>
+<li>item two<ul>
<li>sublist</li>
<li>sublist</li>
</ul>
</li>
@@ -17,11 +15,9 @@
<a href="https://github.com/jgm/commonmark.js">commonmark.js</a>, the<br>
JavaScript reference implementation.</p>
<ol>
<li>item one</li>
-<li>
-<p>item two</p>
-<ul>
+<li>item two<ul>
<li>sublist</li>
<li>sublist</li>
</ul>
</li>
Observed Results:
- What happened? This could be a description, log output, etc. Already explained above.
Expected Results:
- What did you expect to happen? Line numbers do not overflow.
Relevant Code:
Overridding the line number position fixes the issue,
.d2h-code-side-linenumber{
position: relative;
}
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 20 (6 by maintainers)
modify css
have a try
have a try ,that fixed my problem
Yes, the problem we are trying to solve here is to have a limited height, but the HTML and CSS are not ready for this. It would need a re-write to make it work without breaking the current functionality.
I think it is the same as this issue https://github.com/rtfpessoa/diff2html/issues/185
Add
position:relativeto.d2h-diff-tableclass will work and line number still show the same across browsers. The CSS did not wrap element that haveposition:absolutethat’s why it will be always break when it is not in the normal element. (in the element that have limited height, overflow scroll will breakposition:absoluteif there is noposition:relativewrap on it.)Read more about this at -> https://css-tricks.com/absolute-positioning-inside-relative-positioning/ and -> https://dzone.com/articles/css-position-relative-vs-position-absolute and -> https://developer.mozilla.org/en-US/docs/Web/CSS/position
This mean…
tdwithposition:absolutewill be working fine on static page. Scroll page down, thetdwill be move up as its position. But iftdwithposition:absoluteis in thedivwithheight: 300px; overflow: auto;, when scroll it does not scroll the page but scroll thedivbuttdposition is still stick to the page -> then it’s broken. Wrapposition:absolutewithposition:relativeon its parent element fix this problem and did not break the layout.