Search code examples
htmlcssoverlayspotlight

Spotlight element with css


I have a spotlight circle, I'm trying to place it in the bottom left of the screen and to make the overlay take full height and width but it's not working perfectly, here is the code:

.spotlight{
display: block;
  float: left;
  background: radial-gradient(10px 10px at 110px 30px, transparent 0, transparent 60px, rgba(0, 0, 0, 0.5) 65px);
  background: -moz-radial-gradient(10px 10px at 400px 30px, transparent 0, transparent 95px, rgba(0, 0, 0, 0.5) 100px);
  background: -webkit-radial-gradient(10px 10px at 400px 30px, transparent 0, transparent 95px, rgba(0, 0, 0, 0.5) 100px);
  background: -o-radial-gradient(10px 10px at 400px 30px, transparent 0, transparent 95px, rgba(0, 0, 0, 0.5) 100px);
  height: 100%;
  pointer-events: none;
  position: absolute;
  width: 100%;
  z-index: 100000000;
  bottom: 0px;
  }
<div class="spotlight"></div>


Solution

  • You can correct the gradient like below:

    from the left it should be 65px and from the top 100% - 65px. (you can replace 65px with any value you want)

    .spotlight{
      background: radial-gradient(10px 10px at 65px calc(100% - 65px), transparent 0, transparent 60px, rgba(0, 0, 0, 0.5) 65px);
      height: 100%;
      pointer-events: none;
      position: absolute;
      top:0;
      left:0;
      width: 100%;
      z-index: 100000000;
      bottom: 0px;
      }
    <div class="spotlight"></div>

    You can also simplify like this:

    .spotlight{
      background: radial-gradient(circle at 65px calc(100% - 65px), transparent 60px, rgba(0, 0, 0, 0.5) 65px);
      height: 100%;
      pointer-events: none;
      position: absolute;
      top:0;
      left:0;
      width: 100%;
      z-index: 100000000;
      bottom: 0px;
      }
    <div class="spotlight"></div>