css - 向 SVG 元素添加斜 Angular 和浮雕?

标签 css svg svg-filters emboss

所以我想知道是否可以向 SVG 元素添加斜 Angular 和浮雕?

我的矩形元素的 CSS 是这样的:

rect {
  fill: #e8e9eb;
  stroke: black;
  stroke-width: 1px;
  width: 70;
  height: 30;
}

我试图将这个 CSS 添加到它取自 here :

-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.5), inset 0 -2px 0 rgba(0,0,0,.25), inset 0 -3px 0 rgba(255,255,255,.2), 0 1px 0 rgba(0,0,0,.1);
-moz-box-shadow: inset 0 1px 0 rgba(255,255,255,.5), inset 0 -2px 0 rgba(0,0,0,.25), inset 0 -3px 0 rgba(255,255,255,.2), 0 1px 0 rgba(0,0,0,.1);
box-shadow: inset 0 1px 0 rgba(255,255,255,.5), inset 0 -2px 0 rgba(0,0,0,.25), inset 0 -3px 0 rgba(255,255,255,.2), 0 1px 0 rgba(0,0,0,.1);

我相信它不工作的原因是因为它使用 fill 而不是 background 但我不确定。有没有办法在使用 fill CSS 样式时做到这一点?如果没有,最好的方法是什么?

最佳答案

您想使用 SVG Filter effects倾斜任意 SVG 内容。

这是一个有两个版本的斜 Angular 的例子:
http://jsfiddle.net/rcd5L/

<svg xmlns="http://www.w3.org/2000/svg" viewBox="-10 -10 120 100">
  <filter id="Bevel" filterUnits="objectBoundingBox" x="-10%" y="-10%" width="150%" height="150%">
    <feGaussianBlur in="SourceAlpha" stdDeviation="3" result="blur"/>
    <feSpecularLighting in="blur" surfaceScale="5" specularConstant="0.5" specularExponent="10" result="specOut" lighting-color="white">
      <fePointLight x="-5000" y="-10000" z="20000"/>
    </feSpecularLighting>
    <feComposite in="specOut" in2="SourceAlpha" operator="in" result="specOut2"/>
    <feComposite in="SourceGraphic" in2="specOut2" operator="arithmetic" k1="0" k2="1" k3="1" k4="0" result="litPaint" />
  </filter>
  <filter id="Bevel2" filterUnits="objectBoundingBox" x="-10%" y="-10%" width="150%" height="150%">
    <feGaussianBlur in="SourceAlpha" stdDeviation="0.5" result="blur"/>
    <feSpecularLighting in="blur" surfaceScale="5" specularConstant="0.5" specularExponent="10" result="specOut" lighting-color="white">
      <fePointLight x="-5000" y="-10000" z="0000"/>
    </feSpecularLighting>
    <feComposite in="specOut" in2="SourceAlpha" operator="in" result="specOut2"/>
    <feComposite in="SourceGraphic" in2="specOut2" operator="arithmetic" k1="0" k2="1" k3="1" k4="0" result="litPaint" />
  </filter>
  <rect width="100" height="40" filter="url(#Bevel)" />
  <rect y="50" width="100" height="40" filter="url(#Bevel2)" />
</svg>

关于css - 向 SVG 元素添加斜 Angular 和浮雕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18517763/

相关文章:

javascript - php强制页面重新加载包括

css - 多边框(带边框的 div 上的 Div)

html - 如何在 Angular/TypeScript 的 *ngFor 中切换行的背景颜色?

javascript - 确定两条线之间 SVG 路径上的 Angular

CSS 模糊过滤器在滚动和悬停时中断

twitter-bootstrap - 背景透明不起作用

javascript - 允许 SVG 文本在 Angular 中可编辑吗?

node.js - Node JS - 加载和修改 SVG 文件

css - SVG 过滤器使元素在 Safari 和移动版 Chrome 中不可见

html - SVG 滤镜 feFlood 'flood-color' 属性是否支持渐变作为输入?