Skip to content

Instantly share code, notes, and snippets.

@adamcbrewer
Created June 25, 2013 16:04
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save adamcbrewer/5859738 to your computer and use it in GitHub Desktop.
Save adamcbrewer/5859738 to your computer and use it in GitHub Desktop.
CSS: overflow/border-radius mask bug-thingy
/*
* There's a bug in Chrome/Safari using overflow:hidden with border-radius. This mask fixes it.
* Solution: http://stackoverflow.com/questions/5736503/how-to-make-css3-rounded-corners-hide-overflow-in-chrome-opera/10296258#10296258
*/
.masked {
position: absolute;
border-radius: 10px;
overflow: hidden;
/* this fixes the overflow:hidden in Chrome */
-webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);
}
@JonathanBristow
Copy link

Seems this is still a bug. Thanks for the fix, saved me hours!

Copy link

ghost commented Oct 28, 2015

This is still a bug, and this fixed it. Thank you.

@poiuty
Copy link

poiuty commented Jan 15, 2016

Thank you.

@sergeylaptev
Copy link

There is cleaner mask for it:

mask-image: radial-gradient(circle, white 100%, black 100%);

@fregante
Copy link

fregante commented Oct 5, 2016

Also, possibly lighter, using a path rather than a black/white mask:

.masked {
   -webkit-clip-path: circle(50% at 50% 50%);
}

@19h47
Copy link

19h47 commented Oct 25, 2016

Thank you so much, it saved my life!

@oodzchen
Copy link

I just found another way to fix it,set the mask element as positioned and z-index greater than -1:

.masked {
    position: absolute;
    border-radius: 10px;
    overflow: hidden;
   /* z-index is the key */
    z-index: 1;
}

@RickFrom1987
Copy link

2018 is this still an issue?

@RubenPauwels1
Copy link

RubenPauwels1 commented May 23, 2018

Thank you, this fixed my problem!

@RickFrom1987 This is still an issue in 2018...

@eyaleizenberg
Copy link

Thank you so much @sergeylaptev and @adamcbrewer !
Both your solutions worked for me!
I came here because I had an element with border radius and elements with position sticky where were "overflowing" beyond their container.

@libid0nes
Copy link

Thank you very much, this solved my problem!
P.S. greetings from 2020

@adamcbrewer
Copy link
Author

@Libidine you're welcome! It would be amazing if this is still an issue :)

@yunyanliluo
Copy link

Thank you so much! You also saved me~ I hava tried for 3.5 hours this evening! Thanks to your solution I fixed my problem

@benistary
Copy link

Great! 2022 and still relevant. 👍

@joosia
Copy link

joosia commented Apr 7, 2023

Oh yes, thank you! Such a pain in the ass. And still relevant in 2023... 😄

@marinagallardo
Copy link

Works like charm. Thanks for sharing <3

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