cssborderbackground-colorrgbabox-shadow

How do I eliminate a gap between a box-shadow and a div background when using partially transparent rgba() values



For some reason, when using partially transparent rgba() background-color and box-shadow color values on an element with a non-fixed (percent-based) border-radius, it renders a tiny transparent gap at the edge of the div element between the background and the box-shadow.


My quesion is this...

How do I get rid of this gap, while maintaining a non-fixed border-radius with background-color and box-shadow transparency?


Gap between box shadow and div background

Here is the code:

html {
  background-color: #cef;
  font-family: arial;
}
#background-underlay{
  background-color: white;
  text-align: center;
  margin-top: 5%; 
  padding-top:0px;
  color: black;
}
#overlay-div{
  display: flex;
  position: fixed;
  top: 15%;
  left: 15%;
  height: 70%;
  width: 70%;
  background-color: rgba(0, 0, 40, 0.8);
  color: white;
  border-radius: 50%;
  box-shadow: 0px 0px 2em 2em rgba(0, 0, 40, 0.8);
}
<h1 id="background-underlay">Background Text</h1>
<div id="overlay-div"></div>


Description of the sample element:

Things I've tried which were not successful:


Things which (at least partially) removed the gap, which are not solutions:


Solution

  • A blur filter can give you the same output or at least a similar one without issue:

    html {
      background-color: #cef;
      font-family: arial;
    }
    #background-underlay{
      background-color: white;
      text-align: center;
      margin-top: 5%; 
      padding-top:0px;
      color: black;
    }
    #overlay-div{
      display: flex;
      position: fixed;
      top: 8%;
      left: 8%;
      height: 81%;
      width: 81%;
      background-color: rgba(0, 0, 40, 0.8);
      filter:blur(1.5em);
      color: white;
      border-radius: 50%;
    }
    <h1 id="background-underlay">Background Text</h1>
    <div id="overlay-div"></div>