Skip to content

Instantly share code, notes, and snippets.

@domske
Last active June 26, 2024 17:18
Show Gist options
  • Save domske/b66047671c780a238b51c51ffde8d3a0 to your computer and use it in GitHub Desktop.
Save domske/b66047671c780a238b51c51ffde8d3a0 to your computer and use it in GitHub Desktop.
Bugfix (Workaround) for Safari (iOS): Border radius with overflow hidden does not work as expected.

There is a bug in Safari when using border-radius and overflow: hidden. Especially when applying transform to a child. In this case, overflow: hidden does not always work. The child ignores the border radius and overflows. It's a very old bug. And sadly it seems that it will never be fixed. Anyway, we can't wait for it.

There are some workaround. We need to place the element with the overflow attribute into a stacking context. I've tested the following workarounds on the latest version of iOS (14.4). You can choose what you want. But you should search the web for the particular attribute. (e.g. will-change should be rarely used. See docs)

Use this on the element with overflow: hidden and border-radius:

z-index: 0;
/* Or another value. */
/* The position may need to be set to e.g. relative or absolute. */

or

transform: translateZ(0);
/* Or translate3d(0, 0, 0) or other values. */

or

mask-image: radial-gradient(white, black);
/* Maybe: -webkit-mask-image: -webkit-radial-gradient(white, black); */

or

will-change: transform;
/* Read the docs first. Apparently it should be used carefully. */

Let me know if this fixed your problem or not. Personally, I use transform or z-index. These are probably the most harmless properties. But feel free to post your opinion and other great solutions.

@NeroTesalo
Copy link

I love you for this! Solution 2: transform: translateZ(0) save my life free from this awful bug

@sohammondal
Copy link

Awesome!! transform: translateZ(0); works for me. ❤️

@PinkiNice
Copy link

🫡🫡🫡🫡🫡🫡🫡🫡

@seamlink-aalves
Copy link

transform: translateZ(0); did it for me. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment