Sphinx alabaster theme scroll inside of fixed sidebar
Asked Answered
C

2

5

I have made a sphinx project/documentation (using the alabaster theme) that has a fixed sidebar on the left (containing the TOC), but has too much content to display on the screen. How can I make that content scrollable while still allowing the right side (the main text) to be scrollable separately?

I have seen this question which is similar, but only deals with your own website, and not a sphinx alabaster themed documentation.

Crescentic answered 14/7, 2019 at 23:20 Comment(2)
Look at the generated HTML and CSS and compare it with a theme that does what you want, maybe sphinx_rtd_theme. Copy the CSS for the features you want into the Alabaster theme.Espresso
One problem is that the CSS in the sphinx_rtd_theme is obfuscated into 1 line, and it is hard to read. I'll try nevertheless.Crescentic
C
8

It turns out the solution is hidden on this github PR. Create a file named custom.css that is in the _static folder. Then, in conf.py, add this code:

html_static_path = ['_static']

What that does is tell sphinx to override the default CSS, allowing you to enter your own CSS. Then, in the custom.css file, add this code:

div.sphinxsidebar {
    max-height: 100%;
    overflow-y: auto;
}

That code makes the scroll bar appear and is what worked for me. This is what the end result looks like: Documentation with scroll bar

Crescentic answered 15/7, 2019 at 13:17 Comment(0)
S
0

Since the OP is using Alabaster theme, using theme option fixed_sidebar helps both pinning the sidebar to the top as well as invoking the scrollbar.

html_theme_options = {
    ...,
    'fixed_sidebar': True,
}

Checked with rel 0.7.16 and it works.

Succussion answered 8/8, 2024 at 17:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.