Skip to content

Commit 4418f5f

Browse files
committed
fix: Line numbers when scrolling
1 parent 6a02f2d commit 4418f5f

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/ui/css/diff2html.css

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,13 @@
7474
font-size: 13px;
7575
}
7676

77-
.d2h-diff-tbody > tr > td {
78-
height: 20px;
79-
line-height: 1;
80-
}
81-
8277
.d2h-files-diff {
8378
display: block;
8479
width: 100%;
8580
height: 100%;
8681
}
8782

8883
.d2h-file-diff {
89-
overflow-x: scroll;
9084
overflow-y: hidden;
9185
}
9286

@@ -102,13 +96,15 @@
10296
.d2h-code-line {
10397
display: inline-block;
10498
white-space: nowrap;
105-
padding: 0 10px;
99+
/* Compensate for the absolute positioning of the line numbers */
100+
padding: 0 8em;
106101
}
107102

108103
.d2h-code-side-line {
109104
display: inline-block;
110105
white-space: nowrap;
111-
padding: 0 10px;
106+
/* Compensate for the absolute positioning of the line numbers */
107+
padding: 0 4.5em;
112108
}
113109

114110
.d2h-code-line del,
@@ -149,26 +145,27 @@
149145
.line-num1 {
150146
box-sizing: border-box;
151147
float: left;
152-
width: 40px;
148+
width: 3.5em;
153149
overflow: hidden;
154150
text-overflow: ellipsis;
155-
padding-left: 3px;
151+
padding: 0 0.5em 0 0.5em;
156152
}
157153

158154
.line-num2 {
159155
box-sizing: border-box;
160156
float: right;
161-
width: 40px;
157+
width: 3.5em;
162158
overflow: hidden;
163159
text-overflow: ellipsis;
164-
padding-left: 3px;
160+
padding: 0 0.5em 0 0.5em;
165161
}
166162

167163
.d2h-code-linenumber {
168164
box-sizing: border-box;
169-
width: 86px;
170-
padding-left: 2px;
171-
padding-right: 2px;
165+
width: 7.5em;
166+
/* Keep the numbers fixed on line contents scroll */
167+
position: absolute;
168+
display: inline-block;
172169
background-color: #fff;
173170
color: rgba(0, 0, 0, 0.3);
174171
text-align: right;
@@ -177,11 +174,16 @@
177174
cursor: pointer;
178175
}
179176

177+
.d2h-code-linenumber:after {
178+
content: '\200b';
179+
}
180+
180181
.d2h-code-side-linenumber {
182+
/* Keep the numbers fixed on line contents scroll */
183+
position: absolute;
184+
display: inline-block;
181185
box-sizing: border-box;
182-
width: 56px;
183-
padding-left: 5px;
184-
padding-right: 5px;
186+
width: 4em;
185187
background-color: #fff;
186188
color: rgba(0, 0, 0, 0.3);
187189
text-align: right;
@@ -192,6 +194,10 @@
192194
text-overflow: ellipsis;
193195
}
194196

197+
.d2h-code-side-linenumber:after {
198+
content: '\200b';
199+
}
200+
195201
.d2h-code-side-emptyplaceholder,
196202
.d2h-emptyplaceholder {
197203
background-color: #f1f1f1;

0 commit comments

Comments
 (0)