CSS透明径向渐变问题

时间:2018-07-05 18:06:11

标签: html css image gradient

我是CSS渐变的新手,并试图掌握它,我试图应用白色透明的CSS渐变来用背景图像围绕圆形div的边界。不幸的是,我得到的效果不是所需要的,我该如何制作它,以使图像看起来不那么被渐变所遮盖,并且渐变不那么宽,我想让它仅影响图像的边界图像,例如距外环深约30像素。

我的代码:

.transparent-gradient::after {
  content: "";
  background-image: radial-gradient(ellipse at center, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  }
  .transparent-gradient{
  width:300px; height:300px; margin:20px 0px; align-self:center;position:relative; overflow:hidden; background-color:red;border-radius:50%; background-size:cover; background-position:center; background-image:url('https://images.unsplash.com/photo-1530279281203-4c60af01ee58?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=02b66d237286bcb2a071ed6c1e72adf3&auto=format&fit=crop&w=1950&q=80');
  }
<div class="transparent-gradient" style=""></div>

1 个答案:

答案 0 :(得分:2)

.transparent-gradient::after {
  content: "";
  background: radial-gradient(ellipse at center, rgba(255,255,255,0) 40%,rgba(255,255,255,.9) 100%);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.transparent-gradient{
  width:300px; 
  height:300px; 
  margin:20px 0px; 
  align-self:center;
  position:relative; 
  overflow:hidden; 
  background-color:red;
  border-radius:50%; 
  background-size:cover; 
  background-position:center; 
  background-image:url('https://images.unsplash.com/photo-1530279281203-4c60af01ee58?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=02b66d237286bcb2a071ed6c1e72adf3&auto=format&fit=crop&w=1950&q=80');
}
<div class="transparent-gradient" style=""></div>

对于rgba(255,255,255,0) 40%40%指定“ size”。 使用rgba(255,255,255,.9) 100%的.9,可以使白色变硬(来自rgb A 的不透明度/ Alpha)。 1是完全白色.5white,透明度为50%