Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random extra space at end of horizontally scrollable table

Tags:

I'm using pygments to display CSS-styled code on a static HTML page, but am running into a weird bug that renders the <pre> tag wrongly in Safari. As you can see in this fiddle when you scroll to the right in the table, the charcoal background (which is set on the <pre>) stops before the text stops and the remainder of the text is not very readable.

Some observations:

  • This works fine in Chrome
  • If I remove the blank line inside the <pre></pre> everything works as expected
  • Removing the <span class="s"></span> works as well
  • Adding overflow: auto to the <pre> gives me 2 scroll bars that scroll independently of each other

I've reduced this problem as much as possible (as seen in the fiddle). The HTML output I can't change, but I can modify the CSS as much as I want, so that's the solution I'm looking for.

I tried this on Safari 9.1 on OS X 10.11.4. Does anyone understand what's going on?

Screenshot:

screenshot

like image 439
Scott Berrevoets Avatar asked Apr 05 '16 07:04

Scott Berrevoets


People also ask

How do I find out what is causing my horizontal scroll?

To find out which elements cause a horizontal scrollbar, you can use the devtools to delete elements one by one until the scrollbar disappears. When that happens, press ctrl/cmd Z to undo the delete, and drill down into the element to figure out which of the child elements cause the horizontal scrollbar.

What is scrolling overflow?

overflow: scrollSetting the value to scroll , the overflow is clipped and a scrollbar is added to scroll inside the box. Note that this will add a scrollbar both horizontally and vertically (even if you do not need it): You can use the overflow property when you want to have better control of the layout.

How do you make an overflow scroll horizontal?

Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line. Here the scroll div will be horizontally scrollable.


1 Answers

Updated Answer

According to the documentation here on pygment.org you have some control over the resultant HTML but as you pointed out it is limited.

I have used CSS pseudo and counter-increments for line numbers - being more robust and flexible. Counts are directly linked to each span and ignore anything that should not be a line number (eg comment or text) - as shown in the first example below.

The structure is;

<pre>
    var = <span></span><span></span><span></span>
</pre>

Result 1

See this FIDDLE.


In the following example - the first-child has an inline-block;

Result 2

See this FIDDLE


Original Answer

Use the white-space property with nowrap.

.highlight pre {
    color: #C1C2C3;
    white-space: nowrap;
}

JS Fiddle

Below fiddles demo how you can match line-heights for single or multiple lines;

.highlight pre {
    color: #C1C2C3;
    white-space: nowrap;
    margin:0;
    line-height: 2;
}

.highlighttable .linenodiv pre {
    line-height: 2;
    margin:0;
}
  1. Multiple Lines
  2. Single Line
like image 88
Jabuka Avatar answered Sep 28 '22 03:09

Jabuka