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

Default CSS preventing embedded tweets from having transparent borders #6889

Closed
4 tasks done
perpil opened this issue Mar 8, 2024 · 20 comments
Closed
4 tasks done

Default CSS preventing embedded tweets from having transparent borders #6889

perpil opened this issue Mar 8, 2024 · 20 comments
Labels
bug Issue reports a bug not fixable Issue concerns an unfixable bug

Comments

@perpil
Copy link
Sponsor Contributor

perpil commented Mar 8, 2024

Context

I'm trying to embed a tweet into my site. In dark mode, borders on a tweet show up as white and not transparent. It has something to do with material css. If I create a blank html page with a dark background and embed a tweet the corners look fine. I cut this as a discussion originally but it also happens on the mkdocs material site. I have been unable to pinpoint which piece of material CSS is causing this.

image

Bug description

Material's CSS is causing corners on embedded tweets to look bad in dark mode when they are rendered.

Related links

Reproduction

9.5.13+insiders.4.53.1-css-twitter-embed-corners.zip

Steps to reproduce

  1. Embed a tweet on any mkdocs material site in dark mode. Or look at this page in dark mode.
  2. Corners will be square and white instead of the color of the background.

Browser

No response

Before submitting

@squidfunk squidfunk added the needs investigation Issue must be investigated by the maintainers label Mar 9, 2024
@alexvoss
Copy link
Sponsor Collaborator

alexvoss commented Mar 9, 2024

The tweet is embedded using an iframe. That means that all of the styling of it is controlled by Twitter and is unrelated to the styling applied by Material. I am afraid that there is no pure CSS way to influence the styling. You can get Twitter to render the tweet in dark mode by adding data-theme="dark" to the embed code. However, that makes things worse...

image

I could not find anything on the embedded tweet parameter reference that would change the background of the iframe. Not sure if it is possible to do from outside as the browser security model should prevent this? Unless you can convince Twitter to put a dark themed embedded tweet into an iframe with a dark background, I am afraid you may be stuck. That said, I am not an expert on matters of web design, so there is a chance I have missed a trick.

@squidfunk
Copy link
Owner

@perpil is right – it does not happen with the mkdocs and readthedocs themes, only material seems to replace the transparent background. I've not yet managed to find out why. It's very weird. Here's readthedocs with red background for demonstration purposes. If you switch to material, the background appears.

Bildschirm­foto 2024-03-09 um 13 52 03

@squidfunk squidfunk added bug Issue reports a bug and removed needs investigation Issue must be investigated by the maintainers labels Mar 9, 2024
@squidfunk
Copy link
Owner

This line is causing the problem:

If you remove the declaration, borders are transparent. I'm not sure why. This might be a bug in or an interference with Twitter's CSS. We should not remove the color-scheme declaration, because it denotes to the browser that it should render unstyled UI elements in light or dark appearance. For this reason, I've added a new declaration in 1d6dd99, which will reset the property for iframes only, fixing the problem:

Bildschirm­foto 2024-03-09 um 14 04 28

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Mar 9, 2024
@perpil
Copy link
Sponsor Contributor Author

perpil commented Mar 10, 2024

Thanks for the quick work, I tested it and it does indeed resolve it for the repro I attached, but when you set a palette, it doesn't. You can repro by toggling to dark mode with what I attached. Is there a fix that works if for all scenarios?

9.5.13+insiders.4.53.1-css-twitter-embed-palette.zip

@squidfunk
Copy link
Owner

Hmm, indeed, very strange. I'd expect that color-scheme: initial resets the value appropriately, but it doesn't. My testing shows that color-scheme: auto seems to fix both cases, so I applied it in 8244ff3. Can you confirm?

@perpil
Copy link
Sponsor Contributor Author

perpil commented Mar 11, 2024

I'm on the insiders version, can you push it there too?

@squidfunk
Copy link
Owner

I just did, could you please check master?

@perpil
Copy link
Sponsor Contributor Author

perpil commented Mar 11, 2024

Hmm, it still looks like this for me on Firefox 123.0 Mac:

image

But it looks fine on Chrome 122:

image

@squidfunk
Copy link
Owner

I have not tested Firefox. I'll look into it again. This is really weird...

@squidfunk
Copy link
Owner

Related: https://fvsch.com/transparent-iframes

@squidfunk
Copy link
Owner

I think it's fixed with 750b798 (already on Insiders). color-scheme: light omits the background in Chrome, Safari and Firefox on macOS. However, reading the article, it seems to be underspec'd or a browser bug.

@perpil
Copy link
Sponsor Contributor Author

perpil commented Mar 11, 2024

That did it! Thanks!

@squidfunk
Copy link
Owner

Released as part of 9.5.14.

@squidfunk
Copy link
Owner

squidfunk commented Mar 23, 2024

The changes had another side effect – now Giscus rendering is broken in Chrome. I'm not yet sure how we can ensure that both work. It seems to be an inconsistency between Chrome and Firefox.

@squidfunk
Copy link
Owner

I'm sorry, but we have to revert the changes we made to fix the issue mentioned here. The reason is that I currently see no way forward to fix this in a general fashion. If we apply color-scheme to .md-typeset iframe, it will override any value set by the iframe itself. For instance, this will lead to Giscus looking like this (screenshot from our website right now):

Bildschirm­foto 2024-03-23 um 08 29 06

Twitter expects us to set color-scheme to light, or you will get the borders we tried to fix here. Giscus expects us to set it to light dark. Thus, it is very much dependent on the contents of the iframe what value you need. Another option would be to refrain from setting color-scheme entirely, but would decrease accessibility, as unstyled form elements will now always appear light, even in dark mode. We could try to use a selector like .md-typeset :not(iframe), but that is even more invasive and have unforeseen other side effects, as it would mean that this selector would apply to every element inside .md-typeset, except for iframes.

For this reason, I decided to revert the changes we made in 750b798 until a better solution is found. I'm quite at the end of ideas how to support borderless arbitrary iframes. If somebody cooks up a solution, please create a PR!

@squidfunk squidfunk added not fixable Issue concerns an unfixable bug and removed resolved Issue is resolved, yet unreleased if open labels Mar 23, 2024
@squidfunk
Copy link
Owner

squidfunk commented Mar 23, 2024

The ideal solution would be Twitter's CSS setting the value on the iframe, or Firefox fixing the problem.

@perpil
Copy link
Sponsor Contributor Author

perpil commented Mar 23, 2024

Is it possible to override the color-scheme for just twitter tweets in my extra css? The twitter iframe always is inside a div with class twitter-tweet

@squidfunk
Copy link
Owner

squidfunk commented Mar 23, 2024

Yes, of course, this should do the trick:

.twitter-tweet iframe {
  color-scheme: light;
}

@perpil
Copy link
Sponsor Contributor Author

perpil commented Mar 23, 2024

Ok that's a good enough workaround for me if you don't want to pollute the main css with it, I tested it and it works in FF and Chrome, thanks!

@squidfunk
Copy link
Owner

Perfect, thanks! Sorry for the inconvenience this is causing, but I hope my explanation made sense and outlines that the situation is tricky, to say the least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug not fixable Issue concerns an unfixable bug
Projects
None yet
Development

No branches or pull requests

3 participants