Skip to content

hl_lines highlight background doesn't extend to scrollable area in code blocks #153

Description

@Wcowin

Context

When using hl_lines to highlight specific lines in a code block, the highlight background only covers the initially visible portion. When the code content is wider than the container and users scroll horizontally, the highlight background does not extend into the overflow area, making the highlighting appear incomplete and visually broken.

Description

In the current CSS, code uses display: block, so its width equals the pre container width. The .hll class (used for highlighting) also uses display: block, meaning its width is constrained by the container. When code lines exceed the container width and horizontal scrolling occurs, the .hll background cannot extend into the scrolled area.

Related links

Use Cases

Just add the following CSS:

/* Let pre handle horizontal scrolling */
.md-typeset .highlight pre,
.md-typeset pre {
  overflow-x: auto;
}

/* code width = actual content width, not container width */
.md-typeset pre > code {
  display: inline-block;
  min-width: 100%;
  vertical-align: top;
}

/* hll fills full code width, extending to scrollable area */
.md-typeset .highlight .hll,
.md-typeset pre code .hll {
  display: block;
}

Visuals

Before:

Image

After:

https://wcowin.work/blog/Mkdocs/linktech/

Image

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    change requestIssue requests a new feature or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions