css - 盒子阴影无法复制完美的圆形

标签 css

我使用框阴影属性多次复制原始圆,每个阴影具有不同的扩展,请参阅:

.a {
    width: 50px;
    height: 50px;
    background: #EEB850;
    border-radius: 50%;
    position: relative;
    top: 117;
    left: 167;
    box-shadow: 0 0 0 50px #243D83,
        0 0 0 100px #6592CF;
}

但是,阴影并没有复制圆形,而是看起来像带有圆 Angular 的正方形。对此有什么建议吗? Screenshot of the result .

最佳答案

虽然 Edge/Chrome 中存在错误,但解决方法可能是在较大的 before 伪元素上创建具有径向渐变的圆圈。

这是一个简单的例子:

.a {
  width: 50px;
  height: 50px;
  background: #EEB850;
  border-radius: 50%;
  position: relative;
  top: 117px;
  left: 167px;
}

.a::before {
  content: '';
  position: absolute;
  display: inline-block;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400%;
  height: 400%;
  border-radius: 50%;
  background-image: radial-gradient(#EEB850 0 25px, #243D83 25px 50px, #6592CF 50px 75px, transparent 75px 100%);
  background-position: top left;
}
<div class="a"></div>

注意:由于有时会通过径向渐变获得参差不齐的效果,因此代码片段将中心颜色作为其第一个圆圈,以避免边缘效应(元素和径向渐变之间的小间隙)。

关于css - 盒子阴影无法复制完美的圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72157120/

相关文章:

javascript - 如何更改菜单中按钮的颜色,以便用户知道他所在的页面

javascript - 获取我的li所在的ul的id

css - 机器特定字体系列

javascript - 打开多个模态 Materialise CSS

javascript - 当复选框处于非事件状态时,更改背景颜色并隐藏特定 div 中的单选按钮

javascript - 在我的网站上设置文件上传按钮的样式(输入类型 ="file"),它似乎运行良好,但在 iOS 上会发生变化

html - 将类添加到 div 时添加叠加图像

css - CSS :first-child:before in Chrome 的奇怪行为

CSS转换翻译不能滚动

css - 如何在 CSS 中为流过背景图像的渐变的涟漪效果设置动画