Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

will-change breaks showing position absolute div on :hover

I have an issue with will-change. I have no idea why it causes this problem but when I add will-change on wrapper in which I have list with hidden divs (which should show up on hover) it breaks showing that divs. t shows part of it or not at all (depends on browser). Do you have any idea why it breaks that functionality?

Link -> http://jsbin.com/rukanajugi/1/edit?html,css,output

like image 725
Dawid Krajewski Avatar asked Jun 03 '16 09:06

Dawid Krajewski


Video Answer


1 Answers

Contrary to common belief, the will-change property may actually have an impact on the visual appearance of the element, as it creates a new CSS Stacking Context if used with Stacking Context Creating Properties (e.g. position, opacity, transform) BEFORE the actual transformation was made.

This may therefore change the layout, as the order of the layers (which element is above which one) may be changed.

In your case, the creation of the new Stacking Context through will-change: opacity, causes the layout issue. The hidden divs are positioned absolute, therefore don't increase the size of their parents/grandparents and are therefore cropped by the .menu-wrapper, which now has a stacking context.

You have multiple solutions for this, e.g.

  • Use .menu-wrapper { overflow: visible; }
  • Increase the Size like this: .menu-wrapper { height: 200px; }
  • Do not use Stacking Context creating properties on the will-changeattribute. E.g. using .menu-wrapper { will-change: border-width; } won't create any Stacking Context. As Soon as your .menu-wrapper gets properties, which create a Stacking Context (e.g. opacity: 0.9999), it will break again, however.
like image 53
MattDiMu Avatar answered Oct 21 '22 06:10

MattDiMu