Skip to content

Using font size greater than 16 cause docs to render oddly #93171

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

Closed
iamsauravsharma opened this issue Jan 17, 2022 · 12 comments · Fixed by rust-lang/docs.rs#1614
Closed

Using font size greater than 16 cause docs to render oddly #93171

iamsauravsharma opened this issue Jan 17, 2022 · 12 comments · Fixed by rust-lang/docs.rs#1614
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@iamsauravsharma
Copy link

Changing default font size from 16 to 17 on Firefox makes docs.rs page to render oddly.

Default font size: 17

Screenshot_20220117_160326

Default font size: 16

Screenshot_20220117_160350

@SylvainMartel
Copy link

Same behavior in Chrome too if you change the Font Size setting to anything higher then "medium"

@jsha
Copy link
Contributor

jsha commented Jan 18, 2022

That might be related to #92448, which changed our font sizes from px (absolute) to rem (relative to the user's font size). I don't see how that could produce the symptoms you're seeing, but it's related to font sizes.

Do you see this on all crates, or just recently built crates?

@SylvainMartel
Copy link

@jsha Indeed, this seems to only happens on newer crates. Even older version of a crate in problem will display properly, but the most recent one has the problem(ex: https://docs.rs/axum/0.2.4/axum/index.html is fine, but https://docs.rs/axum/latest/axum/index.html has the problem.

@jsha
Copy link
Contributor

jsha commented Jan 18, 2022

A little quick investigation shows this is because the <main> element is in a flexbox alongside the sidebar, and the browser is choosing to shrink it from its default size (but seemingly only when the font size is bigger than default?).

Setting flex-shrink: 0 on <main> seems to fix, but I'm not sure that's the correct solution.

@jsha
Copy link
Contributor

jsha commented Jan 18, 2022

Also, unchecking the main { min-width: 0 } rule (or setting it to auto seems to do the trick. https://developer.mozilla.org/en-US/docs/Web/CSS/min-width

@jsha
Copy link
Contributor

jsha commented Jan 18, 2022

@cynecx in your PR fixing the sidebar to use flexbox (thanks for that!), you had:

main {
	position: relative;
	flex-grow: 1;
	padding: 10px 15px 40px 45px;
	min-width: 0;
}

Do you happen to remember why you set min-width: 0?

@cynecx
Copy link
Contributor

cynecx commented Jan 19, 2022

Setting flex-shrink: 0 on

seems to fix, but I'm not sure that's the correct solution.

Yeah I agree, I don't think that's the proper fix.

Do you happen to remember why you set min-width: 0?

I don't quite remember but I think it was because flex child elements have min-width defaulted to auto that caused the child to overflow the parent.

But I don't think that's the proper fix here.

If we look at the flex container:

image

We can see that the flexbox container isn't utilizing the whole width (because it hasn't been set!). So perhaps the proper fix would be to make the flex container width: 100%? (I've tested it locally and it seems to work just fine)

@jsha
Copy link
Contributor

jsha commented Jan 21, 2022

I propose closing this in favor of #93120 (or moving this issue to the rust repo if that's possible?).

@Nemo157 Nemo157 transferred this issue from rust-lang/docs.rs Jan 21, 2022
@Nemo157
Copy link
Member

Nemo157 commented Jan 21, 2022

@jsha transferred

@Nemo157 Nemo157 changed the title Using font size greater than 16 cause docs.rs to render oddly Using font size greater than 16 cause docs to render oddly Jan 21, 2022
@jsha jsha added A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 21, 2022
@jsha
Copy link
Contributor

jsha commented Jan 22, 2022

@cynecx The width: 100% thing you posted works, but it's unsatisfying. If the issue is lack of an explicit width: 100%, why does this only show up on font sizes >16px?

Here's another possible fix: set font-size: 16px on div.nav-container. The page was previously inheriting font-size: 16px from rustdoc's CSS, which sets that on body. When rustdoc's CSS changes to font-size: 1rem (i.e. respect what the user set), that also affected the font size in the topbar. Since the docs.rs topbar has a fixed height of 33px, this caused some of the elements to overflow the topbar, at which point they interfered with <main>'s ability to automatically grow as far as it needed.

What I like about this solution is it doesn't layer tweaks on top of tweaks. Instead, it's adding back in something explicit that docs.rs was implicitly depending on, but that it shouldn't have been.

@jsha
Copy link
Contributor

jsha commented Jan 31, 2022

This is fixed in rust-lang/docs.rs#1614.

@jam1garner
Copy link
Contributor

jam1garner commented Mar 16, 2022

Since this fix won't retroactively apply to old docs, if anyone else runs into this thread, here's a ublock origin filter that has worked for me:

docs.rs###rustdoc_body_wrapper:style(width: 100% !important;)

(Coincidentally it uses the same hack-fix as cynecx mentioned)

I should note that I observe this issue for non-font reasons (I believe, inspector could be lying to me about font calculations) due to the fact I always view docs in a vertical window (half split (left/right) of a 1080p monitor).

And here's also an untested attempt at using built-in firefox userstyles:

@-moz-document domain(docs.rs) {
    #rustdoc_body_wrapper {
        width: 100% !important;
    }
}

(how to use if you're not familiar with userstyles)

And if you want to check if it works, here's a crate+version which is affected.

Edit: I should note that my issue isn't fixed by the font fix (which I believe(?) is present on the latest docs.rs crate builds), but I didn't actually find much useful info to recreate. It could be an issue with desktop vs mobile detection CSS rules or something similar as that tends to be the issue (sites not supporting vertical desktop view is frustratingly common, unfortunately). All I've got is that it's firefox only. I can make an issue if someone lets me know what the preferred repo for such an issue would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants