HTML Border Interpolation

Viewed 91

Google Chrome draws a red circle when given the following HTML. I first thought this was a bug in Chrome, however Safari also draws a red circle. In Firefox the page appears white though. Is the border interpolation browser specific or does the red circle only appear because of a rendering bug?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>SVG Overflow Experiment</title>
  </head>
  <body>
   <div
      style="
        border-color: white;
        border-radius: 50%;
        width: 200px;
        height: 200px;
        overflow: hidden;
      "
    >
      <svg width="200" height="200">
        <rect width="300" height="300" fill="red" />
        <rect width="400" height="400" fill="white" />
      </svg>
    </div>
  </body>
</html>

1 Answers

Looks like the colors are blending on the round edges. May be an antialiasing issue.

I've added one more rectangle and changed colors to prove the point. In below code remove yellow or blue rectangle and you'll notice they are blending when both present.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>SVG Overflow Experiment</title>
  </head>
  <body>
   <div
      style="
        border-color: white;
        border-radius: 30%;
        width: 200px;
        height: 200px;
        overflow: hidden;
        
      "
    >
      <svg width="200" height="200">
        <rect width="400" height="400" fill="rgba(0,0,255,0.4)" />
        <rect width="300" height="300" fill="yellow"/>
         <rect width="400" height="400" fill="white" />
      </svg>
    </div>
    Testing
  </body>
</html>


If you set mix-blend-mode: hard-light; on svg it removes the blending. You may choose other blending as per your needs.
Or simply adding property filter:brigtness(1) seems to resolve the issue in chrome. I don't know why it works. Setting brightness to 1 is harmless than setting blending bode.

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>SVG Overflow Experiment</title>
</head>
<style>
  div {
    border-color: white;
    border-radius: 50%;
    width: 200px;
    height: 200px;
    overflow: hidden;
  }
  
  svg {
    filter: brightness(1);
    /* or use below */
    /* mix-blend-mode: hard-light; /* choose blending as per your requirement */
  }
</style>

<body>
  <div>
    <svg width="100%" height="100%">
        <rect width="400" height="400" fill="rgba(0,0,255,0.4)" />
        <rect width="300" height="300" fill="yellow" />
        <rect width="400" height="400" fill="white" />
      </svg>
  </div>
  Testing
</body>

</html>

Related