From 994e176b6cccbcab14adfa55d0d9c648d6ac7b3b Mon Sep 17 00:00:00 2001 From: Thomas Hebb Date: Wed, 23 Aug 2023 18:33:45 -0400 Subject: [PATCH] Prevent code badges from scrolling along with code The `::before` trick we've been using to add badges has never interacted well with the `overflow-x: auto` we set on the parent `
`:
`position: absolute` positions relative to the unscrolled container and
doesn't "stick" when the container is scrolled, resulting in the badge
leaving the right edge of the block when wide code is scrolled.

Until now, that issue has been masked by the fact that highlight.js
gives the `` its own `overflow-x: auto`. Since we've stopped using
highlight.js, we need to fix the issue properly.

The root cause is described well in this article[1]. As it demonstrates,
all solutions not involving an extra wrapper div take a lot of code and
are pretty hacky. In addition, the last example--closest to our case--
requires the badge itself to have nested divs, which can't be done with
`::before`.

As such, just use JS to add a wrapper div, which actually simplifies
both the CSS and the JS significantly.

[1] https://www.horuskol.net/blog/2022-04-13/relative-and-absolute-scrolling-blues/
---
 _includes/extensions/code-highlight.html | 98 +++++++++++++-----------
 _sass/yat/_base.scss                     |  9 +--
 2 files changed, 53 insertions(+), 54 deletions(-)

diff --git a/_includes/extensions/code-highlight.html b/_includes/extensions/code-highlight.html
index f2750d8940c..c5782cc96ab 100644
--- a/_includes/extensions/code-highlight.html
+++ b/_includes/extensions/code-highlight.html
@@ -19,67 +19,73 @@
 {%- if badge_enabled -%}
 
 
 
 {%- endif -%}
diff --git a/_sass/yat/_base.scss b/_sass/yat/_base.scss
index be1f842e5e6..e12dc36c171 100644
--- a/_sass/yat/_base.scss
+++ b/_sass/yat/_base.scss
@@ -157,15 +157,8 @@ code {
 
 pre {
   overflow-x: auto;
-  position: relative;
   background-color: #f0f0f0;
-
-  > code {
-    display: inline-block;
-    padding: 20px!important;
-    background-color: transparent;
-    border: 0;
-  }
+  padding: 20px;
 
   table, pre {
     margin-bottom: 0;