Skip to content

Instantly share code, notes, and snippets.

@domske
Last active May 22, 2024 17:19
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.

@tklkalok
Copy link

Nice and Detail workaround, appreciate your effort and hope Apple would some how fix it in the future.

@hirenpanchal1608
Copy link

Nice solution!
transform: translateZ(0); works for me

@JoiGud
Copy link

JoiGud commented Nov 29, 2022

Nice workaround. The translateZ worked for me!

@mosuzi
Copy link

mosuzi commented Dec 5, 2022

Unfortunately, neither those above worked for me :(

@fdambrosio
Copy link

good, it works to fix on ios 16 !

@jowc
Copy link

jowc commented Jan 22, 2023

Thanks. The z-index worked for me. :)

@cesswhite
Copy link

Thank you, two solutions work for me in CSS:
1.- mask-image: radial-gradient(white, black);
2.- will-change: transform;

In UnoCSS/TailwindCSS this class work for me:
will-change-transform

@alexhartan
Copy link

You are the man! This fix just solved a bunch of headaches for me

@SebHex
Copy link

SebHex commented Apr 2, 2023

Using the Tailwind CSS class transform-gpu worked for me

This is similar to using the following CSS:

transform: translate3d(0, 0, 0);

@dsajlovic
Copy link

April 2023 still with the same problem, ONLY in Safari -.-
Thank you for posting workaround :)

@minhoyooDEV
Copy link

life saver

@Frederick-88
Copy link

transform: translateZ(0); works for me in 2023 - thanks a lot!

@btlm
Copy link

btlm commented Apr 20, 2023

z-index: 0; works as charm

@kaiwen-wang
Copy link

kaiwen-wang commented May 15, 2023

confirming tailwind will-change-transform works

@VolodymyrShtef
Copy link

Thanks, z-index did the job

@alexfranco90
Copy link

Thanks, both z-index: 0; and transform: translateZ(0); works for me. In my case will-change: transform works too but i was trying to find an alternative.

@MartinMalinda
Copy link

Thanks!

@hieuthien
Copy link

Thanks you, all thing works with my CSS =]]

@wojciak
Copy link

wojciak commented Nov 20, 2023

❤️

@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

🫡🫡🫡🫡🫡🫡🫡🫡

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