As I tried to make an animated figure (transitions on hover), I found out that the background of my <figure>
displayed near the edges when I apply a border radius: 50% to it, even if my image should occupy all the free space.
For a quick demo that illustrates the problem, check out http://codepen.io/anon/pen/KwMMKz
HTML
<figure> <img src="http://placehold.it/400x400" alt> <figcaption>Demo</figcaption> </figure>
CSS
figure { background-color: red; width: 400px; height: 400px; border-radius: 50%; overflow: hidden; position: relative; } img { border-radius: 50%; width: 100%; transition: opacity 1s ease-out; } figcaption { position: absolute; top: 100%; left: 0; width: 100%; color: hotpink; text-align: center; transition: top 1s ease-out; } figure:hover img { opacity: 0; } figure:hover figcaption { top: 50%; }
Pay attention . I know that placing the background color in the picture: hover is a workaround, but I'm more interested in the reason for this “jagged edge” to appear.
I assume this is due to the AA rendering (or something related) with the browser and that it treats the <figure>
element differently than a multimedia element such as <img>
, but I cannot find any evidence of this online. Is this a bug, is it a "feature", or can I fix it?
Finally, I also know that I could use transform: translateY();
here for animation, but this is not part of my question, so please do not provide it as an answer.
UPDATE 17/12 14:03
It seems that this question is not exclusive to the border radius: 50%. A problem can occur if a wrapper element uses border-radius
in combination with overflow: hidden
when the wrapper contains content that is equal to or larger than the wrapper size.
UPDATE 17/12 14:14
Neither the use of overflow: hidden
in the wrapper element, nor the use of border-radius
on the contained image (or any other child element) seems to be the reason for this, as they can be interchanged and the pixelated edge will still appear.
This, apparently, indicates that this problem is caused only by the fact that 2 DOM elements are in the same place when any kind of boundary radius is applied to the wrapper element and the visible area of the child is limited by the parent.