【问题标题】:Adding 3D effect on image with CSS使用 CSS 在图像上添加 3D 效果
【发布时间】:2019-01-21 15:53:15
【问题描述】:

我正在尝试借助纯 CSS 添加 3D 效果,我想在其中转换此图像:

(这不是真正的图像,而是使用<fa-icon icon="undo" mask="circle" transform="shrink-9"></fa-icon>渲染的 SVG 格式 FontAwesome@)

到这张图片:

但我无法获得确切的效果。我尝试了一些 CSS 技巧,但我坚持以下输出:

我写的SASS是:

.three-d-effect {
    position: relative;

    &:after {
        content: "";
        position: absolute;
        top: 5%;
        left: 10%;
        width: 80%;
        height: 80%;
        border-radius: 100%;
        filter: blur(1px);
        z-index: 2;
        transform: rotateZ(40deg);
        display: block;
        background: radial-gradient(circle at 50% 80%, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0) 74%, white 80%, white 84%, rgba(255, 255, 255, 0) 100%);
    }
}

是否可以通过 CSS 实现所需的 3D 效果?

【问题讨论】:

标签: css css-shapes


【解决方案1】:

这是我的尝试,我还使用 CSS 创建了箭头:

.box {
  width: 100px;
  height: 100px;
  background: 
   url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' width='30' height='30'  fill='lightpink'>  <path d='M6 22 L5.84 22 C30 32 36 36 54 60 C56 62 57 62 56 58 C48 34 46 28 27.16 11.17 C10 0 0 17.83 6 22.17 Z' /></svg>") 65px 10px/30px 30px no-repeat,
   radial-gradient(circle at center,#ff4290 20%,transparent 50%),
   radial-gradient(circle at top right,#ff97c2 15%,#ff5d9f 50%,#c4326e 65%);
  border-radius: 50%;
  position: relative;
  box-shadow:0 0 1px #c4326e;
  filter: brightness(110%);
}

.box:before {
  content: "";
  position: absolute;
  top: 25px;
  left: 25px;
  right: 25px;
  bottom: 25px;
  border: 6px solid white;
  border-left-color: transparent;
  border-radius: 50%;
}

.box:after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  background: 
   linear-gradient(#fff, #fff) left/6px 100% no-repeat, 
   linear-gradient(#fff, #fff) bottom/100% 6px no-repeat;
  top: 22px;
  left: 29px;
}
<div class="box">

</div>

【讨论】:

  • 抱歉@Temani 回复晚了。你真的很亲近。我会尝试调整你的例子
  • 由于您在这里使用了某种 SVG,我需要添加更多信息,这实际上不是图像,而是来自 font-awesome 的 SVG。这会有帮助吗?
  • @ShashankAgrawal 如果它是 SVG,我可能会使用它而不是使用 before/after 来创建效果,我可以将其添加为背景,也许它会使效果更接近
  • @Temnani 我在我的应用程序中实现了你的答案,但我发现你已经硬编码了重做图标和背景颜色。我正在尝试实现的是一个通用的 CSS 类,它可以将类似 3D 的效果应用于任何元素(主要是图像和图标)
  • @ShashankAgrawal generic 如果您不提供一些约束,则不可能。是的,考虑到您关于图标的问题,我已经对整个形状进行了硬编码,我不知道是否有可能产生适用于任何类型图像的通用效果。我们至少需要有一些特定的要求,比如形状总是圆的、浅色的等等……但是创造一个我们可以应用到所有东西的效果,这根本是不可能的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-08
  • 1970-01-01
  • 2015-07-13
  • 1970-01-01
  • 1970-01-01
  • 2017-10-03
  • 2020-02-03
相关资源
最近更新 更多