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

fix gasp between backgrounds of body and sidebar divs #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Trim
Copy link
Member

@Trim Trim commented Jan 17, 2023

The issue is the linear-gradient in the body background seems to not working really correctly with pixel dimensions (in Firefox at least): if you zoom in / out the page you'll see the body background to not always correctly update the rendering (and so you'll see a growing gasp for example).

Due to this issue, there was a gap between the backgrounds of the body and the sidebar elements. PR #354 tried to solve this by adjusting the linear-gradient pixel dimensions, but due to the bug of linear-gradient implementation, it was not working when window was resized or page zoomed.

As the linear-gradient usage in the body background was clearly already a workaround to create two vertical color stripes, we replace it with another workaround using the CSS feature which allows to define multiple background images with different size and position.

First background image is defined with the sidebar color (using linear-gradient with only one color) and the width which resolve the pixel gasp reported in #354 (which means the width should be the branding width + body border width). To be able to define a color as an image, we use again linear-gradient, but, this time it fills all the stripe with the same color, so we won't have error due to linear-gradient implementation.

Second image is defined from the first image position for the rest of the body block with the container color.

This new workaround idea comes from this StackOverflow answer which explain how to create pixel perfect horizontal stripes: https://stackoverflow.com/a/24829344

The issue is the linear-gradient in the body background seems to not working
really correctly with pixel dimensions (in Firefox at least): if you
zoom in / out the page you'll see the body background to not always
correctly update the rendering (and so you'll see a growing gasp for
example).

Due to this issue, there was a gap between the backgrounds of the body and the
sidebar elements. PR linuxfrorg#354 tried to solve this by adjusting the
linear-gradient pixel dimensions, but due to the bug of linear-gradient
implementation, it was not working when window was resized or page zoomed.

As the linear-gradient usage in the body background was clearly already a
workaround to create two vertical color stripes, we replace it with
another workaround using the CSS feature which allows to define multiple
background images with different size and position.

First background image is defined with the sidebar color (using
linear-gradient with only one color) and the width which resolve the
pixel gasp reported in linuxfrorg#354 (which means the width should be the
branding width + body border width). To be able to define a color as an
image, we use again linear-gradient, but, this time it fills all the
stripe with the same color, so we won't have error due to
linear-gradient implementation.

Second image is defined from the first image position for the rest of the body
block with the container color.

This new workaround idea comes from this StackOverflow answer which
explain how to create pixel perfect horizontal stripes:
https://stackoverflow.com/a/24829344
@nud
Copy link
Contributor

nud commented Jan 18, 2023

First background image is defined with the sidebar color (using linear-gradient with only one color) and the width which resolve the pixel gasp reported in #354

The pixel alignment problem was fixed by adding no-repeat the the background: without it Firefox does not anchor the background precisely, it does it in increments of about 5px, because it assumes since the background repeats it's not a big deal, I suppose? When I added the background-size it didn't change anything in my tests.

background-repeat: no-repeat;
background-size: $PX_BRANDING_LARG + $PX_BODY_BORDER_WIDTH_LEFT_RIGHT, auto;
background-position: 0, $PX_BRANDING_LARG + $PX_BODY_BORDER_WIDTH_LEFT_RIGHT;
background-image: linear-gradient($C_CLAIR, $C_CLAIR), linear-gradient($C_CONTAINER, $C_CONTAINER);
Copy link
Contributor

Choose a reason for hiding this comment

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

Well if you use two gradients why not just use two plain colours?

Copy link
Member Author

Choose a reason for hiding this comment

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

background-image CSS rule requires an image, so we can't use directly plain colours. The hack is to use linear-gradiant to create an image with just the plain color.

Due to the usage of background-image, I had to disable the background-repeat, otherwise only one of the colour is rendered everywhere.

@Trim
Copy link
Member Author

Trim commented Jan 18, 2023

The pixel alignment problem was fixed by adding no-repeat the the background: without it Firefox does not anchor the background precisely, it does it in increments of about 5px, because it assumes since the background repeats it's not a big deal, I suppose? When I added the background-size it didn't change anything in my tests.

En fait, il faut toutes les instructions ensemble pour que ça marche.

On dit d'abord que l'a 2 images pour créer le background (les images sont crées avec linear-gradient avec des couleurs simples).

Pour pouvoir afficher les 2 images, je dois supprimer le background-repeat, sinon l'une prend le dessus de l'autre.

Comme on a 2 images, il faut dire la taille d'affichage de chacune avec background-size et leur position dans le bloque background-position.

Avec tout ça, Firefox est capable de faire au pixel près les 2 bandes de couleurs verticales.

En théorie linear-gradient peut le faire lui-même (ça marche très bien avec Blink / Chrome), mais ça ne fonctionne pas bien avec Firefox et Webkit, particulièrement quand on fait des zoom in / out. Firefox a également un pas de environ 5 pixels pour avoir un rendu différent je ne sais pas non plus pourquoi.

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.

3 participants