Fix color contrast issues with ::selection (reverting to browser defaults) (#1208)

The scope of this PR has changed slightly - it now removes all styling of `::selection`, which reverts selected-element highlighting to browser defaults (typically a blue highlight with no text colour changes). It still inadvertently closes #1201.

I've included the original PR body below:

---

This resolves an issue on Firefox where selecting a code block produces white text on a white background, which is not legible. To test: visit https://deploy-preview-1208--just-the-docs.netlify.app/docs/index-test/, and highlight various code blocks in light/dark mode.

I did a bit more digging, and realized a handful of things:

- when I added the new `OneLightJekyll` theme, I inadvertently bundled in a `::selection` class; I've removed it.
    - I'm not really sure why this is a part of the theme in the first place!
    - this is technically the minimum change required to have no more issues
- however, at this point, Firefox now correctly uses the global `::selection`, which is white-on-purple; this is *different* from Chrome, which somehow overrides this for `pre` or `code`; I also (subjectively) think this is harder to read.
- the vast majority of websites default to the browser/user agent stylesheet for code highlighting; for example, [react.dev](https://react.dev)
- so, I've elected to instead default to the browser/user agent stylesheet; this has the nice side effect of making Chrome and Firefox consistent again

Questions for reviewers/community members:

- does this fix the problem for you? what about other browsers?
- do we like having the browser default for code selection, or should we stick to white-on-purple?

Closes #1201.
This commit is contained in:
Matt Wang 2023-04-11 17:28:16 -07:00 committed by GitHub
parent 7404c6f6e0
commit 4d95f9937a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 8 deletions

View File

@ -5,11 +5,6 @@
box-sizing: border-box;
}
::selection {
color: $white;
background: $link-color;
}
html {
@include fs-4;

View File

@ -200,9 +200,6 @@ pre.highlight {
.highlight .gi {
color: #43d089;
}
.highlight ::selection {
background-color: #fff;
}
.highlight .language-json .w + .s2 {
color: #e35549;
}