我有一个聚光灯圆圈,我试图把它放在屏幕的左下角,使覆盖层具有完整的高度和宽度,但它不能完美工作,下面是代码:
.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>
最佳答案
您可以如下更正渐变:
从左边应该是65px
,从上面应该是100% - 65px
。(您可以用任何想要的值替换65px
)
.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>
您也可以这样简化:
.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>