javascript - opacity vs fill-opacity in svg -
what difference in opacity vs 'fill-opacity' in svg?
i referred docs fill-opacity , opacity confused meant fill-opacity: opacity of content of current object vs opacity: transparency of object
the difference name indicates :). fill-opacity applicable fill of element (or in other words, background), stroke-opacity applicable stroke whereas opacity applicable both.
the opacity kind of post-processing operation. is, element (or group) whole (the fill + stroke) rendered , transparency adjusted based on opacity setting whereas fill-opacity , stroke-opacity intermediate steps, transparency individually added stroke , fill. when stroke-opacity , fill-opacity used together, result still not same using opacity (because transparency on fill let fill color show through wherever overlap). can see difference visually in first 2 elements below.
also indicated robert (in comments), fill-opacity doesn't apply image whereas opacity work.
svg { width: 100vw; height: 100vh; } body { background: url(http://lorempixel.com/600/600/nature/1); height: 100vh; } polygon { stroke-width: 3; } <svg viewbox='0 0 40 190'> <polygon points='10,10 30,10 30,30 10,30' fill='steelblue' stroke='crimson' opacity='0.5' /> <polygon points='10,40 30,40 30,60 10,60' fill='steelblue' stroke='crimson' fill-opacity='0.5' stroke-opacity='0.5' /> <polygon points='10,70 30,70 30,90 10,90' fill='steelblue' stroke='crimson' fill-opacity='0.5' /> <polygon points='10,100 30,100 30,120 10,120' fill='steelblue' stroke='crimson' stroke-opacity='0.5' /> <image xlink:href='http://lorempixel.com/100/100/nature/3' x='8.5' y='130' width='23' height='23' stroke='crimson' opacity='0.5' /> <image xlink:href='http://lorempixel.com/100/100/nature/3' x='8.5' y='160' width='23' height='23' stroke='crimson' fill-opacity='0.5' /> </svg> in css world can think of in below snippet. (note not saying equal, there subtle differences between svg , css. attempt explain svg attributes translate in css.)
div { height: 20vh; width: 20vh; margin: 30px auto; font-family: verdana; font-size: 2vw; } div:nth-of-type(1) { opacity: 0.5; background: rgba(70, 130, 180, 1); border: .35vw solid rgba(220, 20, 60, 1); } div:nth-of-type(2) { background: rgba(70, 130, 180, 0.5); border: .35vw solid rgba(220, 20, 60, 1); } div:nth-of-type(3) { background: rgba(70, 130, 180, 1); border: .35vw solid rgba(220, 20, 60, 0.5); } body { background: url(http://lorempixel.com/600/600/nature/1); height: 100vh; } <div></div> <div></div> <div></div>
Comments
Post a Comment