-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Margin inconsistently added to code-toolbar's div
on Prism's site
#3110
Comments
A little more info, turns out that a My own page doesn't have the problem, so I'm guessing the problem is specific to Prism's website. And that led me to poke around other parts of Prism's website. I commented out the I un-commented the script, but commented out the following two lines of code in Lines 263 to 265 in d38592c
So at least it isn't a problem with the Toolbar plugin itself, so I guess it's a little less pressing of an issue. But I'm not very sure how to solve it given that it was implemented because of another bug (#1966)? I'm still not sure what is causing the margin to be transferred inconsistently in Chrome, though. May not be super necessary to figure out why, but I hope it's not a sign of another bug. |
Turns out the difference in behaviour in Chrome and Firefox is caused by I added Seeing the console logs on Firefox made me wonder if the lazy loading of languages via Autoloader had anything to do with the discrepancies in To visualise what the code blocks look like after swapping out Autoloader for manual loading: To summarise, the discrepancy between Chrome and Firefox is due to Firefox being unable to evaluate shorthand properties properly, while the discrepancies of some code blocks having |
div
element on Prism's sitediv
on Prism's site
Okay I think the problem is with Lines 255 to 267 in 3f24dc7
If my understanding isn't wrong (I'm really basing this off the console logs in Firefox, I've not looked at Autoloader's code), when Autoloader loads a new language, the relevant code blocks are repainted. I think it's easier to explain in point form:
So here I can offer a solution, which is to add an if statement to check if the margin transfer had already occurred. If not, then we transfer the margin. (This is on top of modifying the code to use However, I think this is a bit of an XY problem. The original goal of the margin transfer is to give the toolbar some headspace in code blocks on Prism's site (#1966 (comment)). At first I wanted to suggest adding a rule for Anyway, I still went ahead and tried commenting out the margin transfer, and adding As a bonus, the latter two solutions above will get rid of the scrollbar for single-line code blocks when the Coy theme is used (which you can see on the Copy to Clipboard page. I don't know why, but somehow it does. To summarise, I have three solutions in mind:
@RunDevelopment what do you think? (And sorry for the text wall!) |
Thank you for investigating this bug! I think the CSS solution (solution 3) is the best solution. However, I think we can do something even simpler. The main problem is that div.code-toolbar {
display: block;
overflow: auto;
margin: .5em 0;
}
div.code-toolbar > pre {
margin: 0;
} (Sure, I just assumed that the margin of all This means that we won't have to hack the toolbar into position and margin collapsing works naturally. What do you think @hoonweiting? |
@RunDevelopment that's genius! And as for the margin of However, Coy doesn't want to play nicely with that :"( Here's a screenshot some code blocks on the Copy to Clipboard plugin page, with the margin transferred in
(I checked the current website to compare as well, and at least it's the same thing, so no loss there.) It's just Coy though, the other themes are fine. Maybe we can use that method when Coy gets replaced with Coy without Shadows in future? I very much prefer not using negative margins! Also, regarding the problem of the
So I'm not sure what I'm missing! |
It never does... Let's just nuke the shadows: div.code-toolbar > pre:after,
div.code-toolbar > pre:before {
display: none !important;
} Also, we can see that the usually grey border around code blocks disappeared (even before removing the shadows). This is because the
Yes, we should be. Coy is implemented in a pretty weird way which causes loads of problems but enables these cool shadows. Coy without Shadows takes the standard approach to themes but can't implement the shadows (easily).
Because that "cool" theme selector on the right side messes with the layout of pages and overlaps with elements. and without: |
Ah I figured out why the shadows don't show up on the darker-coloured rows. It's because the z-index of the shadows are less than 0, and setting a z-index of EDIT: And then the toolbar doesn't show up. But setting a z-index of 2 on the toolbar will fix that. |
Let's do the simple CSS margin transfer + Coy shadow removal. It doesn't look perfectly ok with Coy (as you said, the position is slightly off) but it's usable and consistent. |
Hmm, I guess I am a bit concerned about removing the shadows on Prism's site, because it's the only way users can 'preview' the theme. If they were to download it, they may be confused as to why their downloaded version has shadows, whereas there aren't shadows on Prism's site. Also here's a screenshot of my previous comment, with the additional z-index properties set (sorry for not including it earlier): |
That's a very good point. I made a PR (#3146) to fix the root cause of all of this: The theme selector's design. |
Aw man, you're amazing! |
Information:
Description
Toolbar adds some margin to its own
div
element on Prism's site, and it does so in a strange manner. For some code blocks it'smargin: 8px 0px;
, for others it'smargin: 0px;
. I have no idea why. (Screenshots below are from Chrome)Example
You can check out #3104 yourself (though it's a little inconvenient), where I am writing some docs on Prism tokens. This can also be seen on the Toolbar, Show Language, and Copy to Clipboard plugin pages, if you open dev tools.
Extra info
pre
element instead of thediv
, but they all getstyle: 0px;
instead of a mix), so that's another thing to look out for.I don't know if this is a problem specific to Prism's website, and/or if there are any other elements at play. I'll poke around more and see what else I can find. Additional help will be appreciated!
Originally discovered here: #3104 (comment)
The text was updated successfully, but these errors were encountered: