Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move parent theme css earlier in the inclusion order #451

Merged
merged 5 commits into from
Aug 22, 2021

Conversation

akhmerov
Copy link
Contributor

Closes #447.

I achieve the desired result by making the theme css file empty (this overrides the basic.css provided by the parent theme), and @importing the basic.css in our own theme.css.

This change should enable removing most of the !important properties (not done yet) and simplify implementing derived themes.

@akhmerov akhmerov marked this pull request as draft August 14, 2021 14:23
@akhmerov akhmerov marked this pull request as ready for review August 14, 2021 14:36
Copy link
Contributor Author

@akhmerov akhmerov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now also went ahead and removed the !important parameters. The style changes are minimal, and can be easily undone if desired.

@@ -1,8 +1,8 @@
// Admonitions CSS originally inspired by https://squidfunk.github.io/mkdocs-material/getting-started/

.admonition {
div.admonition, .admonition{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a more specific selector div.admonition, because this is how admonition styling is specified in basic.css. I leave the more catch-all selector for compatibility and in case someone (me) wants to reuse the styling for colapsible admonitions that use a <details> tag.

@@ -1,8 +1,8 @@
// Admonitions CSS originally inspired by https://squidfunk.github.io/mkdocs-material/getting-started/

.admonition {
div.admonition, .admonition{
margin: 1.5625em auto;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit now overrides the parent theme. Previously this margin was ignored. I am happy to undo this style change if necessary.

Copy link
Collaborator

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a nice change! I think I am a bit confused about what exactly the "blank" stuff is doing, perhaps you could explain here or via a commit to the code?

If I understand, because we weren't specifying a stylesheet we were just inheriting the one that the Sphinx basic template uses. So this explicitly specifies the stylesheet so we don't inherit from Sphinx, but sets it to blank because we really just want our own HTML theming to include the stylesheet manually. Is that right?

@@ -0,0 +1 @@
/* This file is intentionally left blank. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you provide more detail here about why this is blank? Imagine a new developer in the future that hasn't seen any of these issues coming across the CSS file, can we provide enough context that they understand why this is here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explained it now.

pydata_sphinx_theme/static/css/theme.css Show resolved Hide resolved
@akhmerov
Copy link
Contributor Author

If I understand, because we weren't specifying a stylesheet we were just inheriting the one that the Sphinx basic template uses. So this explicitly specifies the stylesheet so we don't inherit from Sphinx, but sets it to blank because we really just want our own HTML theming to include the stylesheet manually. Is that right?

Close, but not exactly. One way or another we use the parent stylesheet. Whether we want to remove it entirely is out of scope for this MR. The problem I'm addressing is that the parent stylesheet is included in the template after ours, leading to problems in overriding the defaults (some were actually overlooked I think). Plus the filename of ours is computed dynamically to avoid cache problems. To avoid this I do two things:

  1. Provide a blank stylesheet to override the inclusion of the parent one in the place where sphinx inserts it.
  2. Manually include the parent stylesheet before ours (that's the @import statement).

Co-authored-by: Chris Holdgraf <choldgraf@gmail.com>
Copy link
Collaborator

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this LGTM - agreed that it's better to have the upstream CSS loaded first so that we can override it if need be. I'll leave open for a little bit in case others have thoughts.

@akhmerov
Copy link
Contributor Author

Thanks. Should I do anything about the lighthouse failing? (I've no idea how my changes are related.)

@akhmerov akhmerov marked this pull request as draft August 14, 2021 23:07
@akhmerov akhmerov marked this pull request as ready for review August 14, 2021 23:09
@akhmerov
Copy link
Contributor Author

@choldgraf didn't notice that the comment syntax was wrong (// doesn't work in css), which in turn broke the render in the latest edit.

@choldgraf
Copy link
Collaborator

Ah whoops, my bad

@drammock
Copy link
Collaborator

Should I do anything about the lighthouse failing? (I've no idea how my changes are related.)

lighthouse is broken on all PRs right now, not related to your changes

@choldgraf choldgraf merged commit 50fa477 into pydata:master Aug 22, 2021
@choldgraf
Copy link
Collaborator

choldgraf commented Aug 22, 2021

ok gonna merge this in since the lighthouse thing is for all projects not just this one. many thanks @akhmerov !

@jorisvandenbossche
Copy link
Member

Thanks for the PR @akhmerov !

Browsing through the demo docs, I noticed some changes that might be related to the CSS changes here (or the order switch):

@jorisvandenbossche
Copy link
Member

So bootstrap has the following CSS for definition lists:

dt {
 font-weight:700
}
dd {
 margin-bottom:.5rem;
 margin-left:0
}

and that is now overwriting what sphinx basic theme does (instead of the other way around):

dd {
    margin-top: 3px;
    margin-bottom: 10px;
    margin-left: 30px;
}

@akhmerov
Copy link
Contributor Author

The xarray output is no longer showing up (https://pydata-sphinx-theme.readthedocs.io/en/latest/demo/demo.html#html vs https://pydata-sphinx-theme.readthedocs.io/en/stable/demo/demo.html#html)

Likely a separate issue. Inspecting the outputs shows that the matching div has a hidden attribute: <div class="xr-wrap" hidden="">. Removing the attribute fixes the problem. Not sure what is the root cause.

@jorisvandenbossche
Copy link
Member

For xarray, I think it is caused by removing the !important from .xr-wrap[hidden]. Adding that back also fixes it. Not fully understanding why though (without the !important, it gets overridden by the [hidden] rule from bootstrap, but I thought that our css came after bootstrap's anyway)

@jorisvandenbossche
Copy link
Member

Not fully understanding why though (without the !important, it gets overridden by the [hidden] rule from bootstrap, but I thought that our css came after bootstrap's anyway)

Ah, but it seems that bootstrap also has an !important there, so that's probably the reason it was needed to overrule it

@akhmerov akhmerov deleted the css-ordering branch August 24, 2021 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reorder CSS files
4 participants