Adding drop shadows to SVG symbols - html
I'm building a website that is very heavy on icons, so I'm working with SVG symbols to reduce duplication. In some cases the design calls for the symbols to have a drop shadow, and not in others. I'm struggling to figure out how I can add a drop shadow.
Example of my SVG:
<svg id="icons-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
...
<symbol id="icon-communications" viewBox="1400 0 200 200">
<title>Communications</title>
<rect style="fill: currentColor" x="1447.3" y="95.3" width="105.3" height="5.3"/>
<rect style="fill: currentColor" x="1447.3" y="78" width="105.3" height="5.3"/>
<polygon style="fill: currentColor" points="1463.2,127.9 1468,130.1 1475.7,113.6 1470.9,111.4 "/>
...
</symbol>
...
</svg>
I then include the icon on page using the standard:
<svg class="icon-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<use xlink:href="#icon-communications"/>
</svg>
I can then set the color of the icon like this:
.icon-svg use {
color: blue;
}
.error .icon-svg use {
color: red;
}
But I can't figure out how to add a drop shadow. I've tried CSS box-shadow, and also filter: drop-shadow(), but neither seem to do anything. e.g.
.someClass .icon-svg use {
color: #fff;
-webkit-filter: drop-shadow( 0 0 20px #000 );
filter: drop-shadow( 0 0 20px #000 );
}
Any help would be appreciated.
Use an SVG Filter:
.icon-svg use {
color: blue;
}
.error .icon-svg use {
color: red;
}
.icon-svg {
-webkit-filter: url(#dropshadowy);
}
<svg id="icons-svg" >
<defs>
<filter id="dropshadowy">
<feGaussianBlur in="SourceAlpha" stdDeviation="4"/>
<feMerge>
<feMergeNode/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
<symbol id="icon-communications" viewBox="1400 0 200 200">
<title>Communications</title>
<rect style="fill: currentColor" x="1447.3" y="95.3" width="105.3" height="5.3"/>
<rect style="fill: currentColor" x="1447.3" y="78" width="105.3" height="5.3"/>
<polygon style="fill: currentColor" points="1463.2,127.9 1468,130.1 1475.7,113.6 1470.9,111.4 "/>
</symbol>
</defs>
</svg>
<svg class="icon-svg" >
<use xlink:href="#icon-communications"/>
</svg>
Related
How to put an image in SVG rounded corner hexagon using HTML and CSS?
I am trying to achieve something like the below using SVG: I have tried many solutions from this platform and so far, I have accomplished this: <svg xmlns="http://www.w3.org/2000/svg" width="327.846" height="318.144" viewBox="0 0 327.846 318.144"> <defs> <style> .a { fill:#000; stroke-width: 25px; stroke: rgba(255, 255, 255, 0.5); } </style> </defs> <path class="a" d="M172.871,0a28.906,28.906,0,0,1,25.009,14.412L245.805,97.1a28.906,28.906,0,0,1,0,28.989L197.88,208.784A28.906,28.906,0,0,1,172.871,223.2H76.831a28.906,28.906,0,0,1-25.009-14.412L3.9,126.092A28.906,28.906,0,0,1,3.9,97.1L51.821,14.412A28.906,28.906,0,0,1,76.831,0Z" transform="translate(111.598) rotate(30)"/> </svg> With the above code, I am able to add stroke but not image. And for below code, I am able to add the image but stroke is not appearing: <svg xmlns="http://www.w3.org/2000/svg" width="327.846" height="318.144" viewBox="0 0 327.846 318.144"> <defs> <style> .a { fill: #000; stroke-width: 25px; stroke: rgba(255, 255, 255, 0.5); } </style> <clipPath id="image"> <path class="a" d="M172.871,0a28.906,28.906,0,0,1,25.009,14.412L245.805,97.1a28.906,28.906,0,0,1,0,28.989L197.88,208.784A28.906,28.906,0,0,1,172.871,223.2H76.831a28.906,28.906,0,0,1-25.009-14.412L3.9,126.092A28.906,28.906,0,0,1,3.9,97.1L51.821,14.412A28.906,28.906,0,0,1,76.831,0Z" transform="translate(111.598) rotate(30)" /> </clipPath> </defs> <image clip-path="url(#image)" height="100%" width="100%" xlink:href="http://placekitten.com/800/800" preserveAspectRatio="xMidYMin slice"></image> </svg> What am I missing to get both onboard? PS: Rounded corners are a must for the outer core and transparent layer. Any help/suggestions will be very helpful. Thanks.
Set fill: transparent / fill: none for the path and use it again, as a child of svg <svg xmlns="http://www.w3.org/2000/svg" width="327.846" height="318.144" viewBox="0 0 327.846 318.144"> <defs> <style> .a { fill: none; stroke-width: 25px; stroke: rgba(255, 255, 255, 0.5); } </style> <clipPath id="image"> <path transform="translate(111.598) rotate(30)" d="M172.871,0a28.906,28.906,0,0,1,25.009,14.412L245.805,97.1a28.906,28.906,0,0,1,0,28.989L197.88,208.784A28.906,28.906,0,0,1,172.871,223.2H76.831a28.906,28.906,0,0,1-25.009-14.412L3.9,126.092A28.906,28.906,0,0,1,3.9,97.1L51.821,14.412A28.906,28.906,0,0,1,76.831,0Z"/> </clipPath> </defs> <image clip-path="url(#image)" height="100%" width="100%" xlink:href="http://placekitten.com/800/800" preserveAspectRatio="xMidYMin slice"></image> <path class="a" d="M172.871,0a28.906,28.906,0,0,1,25.009,14.412L245.805,97.1a28.906,28.906,0,0,1,0,28.989L197.88,208.784A28.906,28.906,0,0,1,172.871,223.2H76.831a28.906,28.906,0,0,1-25.009-14.412L3.9,126.092A28.906,28.906,0,0,1,3.9,97.1L51.821,14.412A28.906,28.906,0,0,1,76.831,0Z" transform="translate(111.598) rotate(30)"/> </svg>
comments on #Vishal Bhatt One more queue: when I increase stroke-width, the curve on the transparent layer becomes a sharp corner. How can I keep that rounded when increasing stroke-width? will help solve the problem - stroke-linejoin:round; Used a wide stroke of 65px while keeping the inner rounding of the stroke For solution instead of clip-Path one can try mask: <svg xmlns="http://www.w3.org/2000/svg" width="327.846" height="318.144" viewBox="0 0 327.846 318.144"> <defs> <style> .a { fill:white; stroke-width: 65px; stroke: rgba(255, 255, 255, 0.5); stroke-linejoin:round; } </style> <mask id="msk"> <path class="a" transform="translate(111.598) rotate(30)" d="M172.871,0a28.906,28.906,0,0,1,25.009,14.412L245.805,97.1a28.906,28.906,0,0,1,0,28.989L197.88,208.784A28.906,28.906,0,0,1,172.871,223.2H76.831a28.906,28.906,0,0,1-25.009-14.412L3.9,126.092A28.906,28.906,0,0,1,3.9,97.1L51.821,14.412A28.906,28.906,0,0,1,76.831,0Z"/> </mask> </defs> <image mask="url(#msk)" height="100%" width="100%" xlink:href="http://placekitten.com/800/800" preserveAspectRatio="xMidYMin slice"></image> </svg> Update Hexagon rotation command transform="rotate(15 124.5 111.5)", here 15 - angle of rotation 124.5 111.5 - Hexagon rotation center coordinates <svg xmlns="http://www.w3.org/2000/svg" width="327.846" height="318.144" viewBox="0 0 327.846 318.144"> <defs> <style> .a { fill:white; stroke-width: 45px; stroke: rgba(255, 255, 255, 0.5); stroke-linejoin:round; } </style> <mask id="msk"> <path class="a" transform="translate(50 50) rotate(15 124.5 111.5)" d="M172.871,0a28.906,28.906,0,0,1,25.009,14.412L245.805,97.1a28.906,28.906,0,0,1,0,28.989L197.88,208.784A28.906,28.906,0,0,1,172.871,223.2H76.831a28.906,28.906,0,0,1-25.009-14.412L3.9,126.092A28.906,28.906,0,0,1,3.9,97.1L51.821,14.412A28.906,28.906,0,0,1,76.831,0Z"/> </mask> </defs> <image mask="url(#msk)" height="100%" width="100%" xlink:href="http://placekitten.com/800/800" preserveAspectRatio="xMidYMin slice"></image> </svg>
Problem with clip-path or masks, is they need to have unique ids if you have multiple SVGs on the page. One way around this is to create the SVG client-side; and generate a unique id for every clip-path While we're at it might as well simplify that Hexagon path Wrapped in a Custom Element (no shadowDOM required with that unique id) you get: <style> svg { width: 148px; background: teal; } </style> <svg-hexed-image ></svg-hexed-image> <svg-hexed-image src="http://placekitten.com/800/800"></svg-hexed-image> <svg-hexed-image rotate="30" src="http://placekitten.com/801/801"></svg-hexed-image> <svg-hexed-image rotate="45" stroke="red" opacity=".5" src="http://placekitten.com/300/300"></svg-hexed-image> <script> customElements.define('svg-hexed-image', class extends HTMLElement { connectedCallback() { let img = this.getAttribute("src") || "http://placekitten.com/120/120"; let strokewidth = this.getAttribute("stroke-width") || "3"; let opacity = this.getAttribute("opacity") || ".5"; let stroke = this.getAttribute("stroke") || "white"; let rotate = this.getAttribute("rotate") || 0; let transform = `transform="rotate(${rotate} 23 23)"`; // make very sure for a unique id: let id = "id" + btoa(img) + (new Date() / 1); let d = `M31 3.5a5 5 90 014 3l8 14a5 5 90 010 5l-8 14a5 5 90 01-4 3h-16a5 5 90 01-4-3l-8-14a5 5 90 010-5l8-14a5 5 90 014-3z`; // now write HTML: this.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 46 46"> <defs><clipPath id="${id}"><path fill="none" ${transform} d="${d}"></clipPath></defs> <image clip-path="url(#${id})" height="100%" width="100%" href="${img}"></image> <path fill="none" stroke="${stroke}" stroke-width="${strokewidth}" ${transform} opacity="${opacity}" d="${d}"/></svg>`; } }); </script>
Apply Glow Effect Filter to Anchor Tag with Transparent Path Child SVG
I would like to create an image map by using an SVG to create the clickpoints. I have been asked to add a glow to the anchor on hover, which I'm currently doing by applying a filter to the anchor tag with CSS on hover. However, the glow only works if the path that is a child of the anchor has a solid fill color, as seen in this CodePen. The SVG used is the following: <svg version="1.1" viewBox="0 0 3686 2074" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <filter id="white-glow" x="-5000%" y="-5000%" width="10000%" height="10000%"> <feFlood result="flood" flood-color="#00bbdc" flood-opacity="1"></feFlood> <feComposite in="flood" result="mask" in2="SourceGraphic" operator="in"></feComposite> <feMorphology in="mask" result="dilated" operator="dilate" radius="10"></feMorphology> <feGaussianBlur in="dilated" result="blurred" stdDeviation="5"></feGaussianBlur> <feMerge> <feMergeNode in="blurred"></feMergeNode> <feMergeNode in="SourceGraphic"></feMergeNode> </feMerge> </filter> <style> a { text-decoration: none; } path:hover { filter: url(#white-glow); } a:hover { filter: url(#white-glow); text-decoration: none; fill: #00BBDC; font-weight: bold; } a:hover text { filter: invert(62%) sepia(97%) saturate(3198%) hue-rotate(150deg) brightness(98%) contrast(101%); font-weight: bold; } </style> </defs> <g> <a href="google.com" target="_top"> <path d="m473.3 564.3-0.6911 207 412.4 78.63-0.4043-180.9z" style="fill:white;stroke-opacity:0;" cursor="pointer" pointer-events="all" /> <text transform="rotate(10.2 222.2 851.7)" style="fill:#808080;font-family:'sans-serif';font-size:40px;line-height:1.25;shape-inside:url(#rect898);white-space:pre" xml:space="preserve"> <tspan x="304.74805" y="648.91602"> <tspan>Ask the experts</tspan> </tspan> </text> </a> </g> </svg> However, I would like to accomplish the same glow effect on hover while giving the path a fill value of "transparent". Could you please give me some guidance as to how to proceed in order to accomplish the same end result that was referenced before while keeping the fill value of the path within the anchor tag to "transparent"? I've read the following Smashing Magazine article in which the author talks about the difference between painted and visible SVG elements. Also, according to an answer to How to have a drop shadow on a transparent rect svg, You can't do this if the original is a fully transparent shape - because of reasons - but you can do this starting from an almost completely transparent original shape and end up with a fully transparent shape surrounded by a normal drop shadow. I used the work around provided and published a Codepen demo with it. However, the "Text" child in the anchor tag gets hidden on hover although it's still present in the SVG. Indeed, the filter is blurring away the text. Could you please tell me is there is any other way? Thanks for your share of expertise on this one.
If you want to retain the contents of the original graphic, then you need to add another line to your filter which pastes the original content on top of your glow. .container { position: relative; max-width: 100%; width: 100%; height: auto; background-size: contain; background-repeat: no-repeat; margin: 0; background:orange; } <div class="container"> <svg version="1.1" viewBox="0 0 3686 2074" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <filter id="white-glow" x="-5000%" y="-5000%" width="10000%" height="10000%"> <feFlood result="flood" flood-color="#00bbdc" flood-opacity="1"></feFlood> <feComposite in="flood" result="mask" in2="SourceGraphic" operator="in"></feComposite> <feMorphology in="mask" result="dilated" operator="dilate" radius="10"></feMorphology> <feGaussianBlur in="dilated" result="blurred" stdDeviation="5"></feGaussianBlur> <feMerge> <feMergeNode in="blurred"></feMergeNode> <feMergeNode in="SourceGraphic"></feMergeNode> </feMerge> </filter> <filter id="trans-shadow"> <feColorMatrix type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 100 0" result="boostedInput"/> <feGaussianBlur stdDeviation="5"/> <feComposite operator="out" in2="boostedInput"/> <feComposite operation="over" in2="SourceGraphic"/> </filter> </defs> <style> a { text-decoration: none; } a:hover { filter: url(#trans-shadow); text-decoration: none; fill: #00BBDC; font-weight: bold; } a:hover text { filter: invert(62%) sepia(97%) saturate(3198%) hue-rotate(150deg) brightness(98%) contrast(101%); font-weight: bold; } </style> <g> <a href="google.com" target="_top" pointer-events="all" > <path d="m473.3 564.3-0.6911 207 412.4 78.63-0.4043-180.9z" style="fill:white;fill-opacity="0.01"stroke-opacity:0;" visibility="visible" /> <text transform="rotate(10.2 222.2 851.7)" style="fill:#808080;font-family:'sans-serif';font-size:40px;line-height:1.25;shape-inside:url(#rect898);white-space:pre" xml:space="preserve"> <tspan x="304.74805" y="648.91602"> <tspan>Ask the experts</tspan> </tspan> </text> </a> </g> </svg> </div>
Add shadow to an SVG element, such as line
So I'm pretty new to SVG but I started playing with a graph. The graph is from here. I've been searching for hours and did only find a half solution to my problem. As you see from the code snippet, if you hover on the graph it "glows". But I want that only the circles and the "joints" would glow when I'm hovering on them. What I tried: Using regular CSS shadowing Using the code that makes "glow" the graph, but only on g elements. Creating a separate SVG both: a) in the main SVG b) separately, and mixing them with position: absolute. (after this the positioning worked weirdly) What should I do to make only the circles and the joints "glow"? *{ box-sizing: border-box; margin: 0; padding: 0; } html, body{ height: 100%; width: 100%; } #import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,500&display=swap'); body { font-family: 'Roboto Mono', monospace; } .graph .labels.x-labels { text-anchor: middle; } .graph .labels.y-labels { text-anchor: end; } .graph { height: 500px; width: 800px; } .graph .grid { stroke: #ccc; stroke-dasharray: 0; stroke-width: 3; } .labels { font-size: 17px; font-weight: 400; } .label-title { font-weight: 500; text-transform: uppercase; font-size: 15px; fill: black; } .data { fill: #f86d36; stroke-width: 1; } .graph .dot-joints { stroke: #f86d36; stroke-dasharray: 0; stroke-width: 3; } svg:hover { -webkit-filter: drop-shadow(0px 0px 4px #f86d36e8); filter: drop-shadow(0px 0px 4px #f86d36e8); } <svg version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="graph" aria-labelledby="title" role="img"> <g class="grid x-grid" id="xGrid"> <line x1="90" x2="90" y1="5" y2="371"></line> </g> <g class="grid x-grid" id="xGrid"> <line x1="90" x2="705" y1="370" y2="370"></line> </g> <g class="labels x-labels"><text x="100" y="400">2008</text><text x="246" y="400">2009</text><text x="392" y="400">2010</text><text x="538" y="400">2011</text><text x="694" y="400">2012</text><text x="400" y="440" class="label-title">Year</text></g> <g class="labels x-labels"><text x="70" y="15">15</text><text x="70" y="131">10</text><text x="70" y="248">5</text><text x="70" y="373">0</text><text x="35" y="200" class="label-title">Price</text></g> <g class="data" data-setname="Our first data set"> <circle cx="95" cy="192" data-value="7.2" r="5"></circle> <circle cx="240" cy="141" data-value="8.1" r="5"></circle> <circle cx="388" cy="179" data-value="7.7" r="5"></circle> <circle cx="531" cy="200" data-value="6.8" r="5"></circle> <circle cx="677" cy="104" data-value="6.7" r="5"></circle> </g> <g class="dot-joints x-grid"> <line x1="95" x2="240" y1="192" y2="141"></line> <line x1="240" x2="388" y1="141" y2="179"></line> <line x1="388" x2="531" y1="179" y2="200"></line> <line x1="531" x2="677" y1="200" y2="104"></line> </g> </svg>
I hope this is what you need: I'm using an svg filter for the shadow. To your code I've added .data circle:hover{filter:url(#f)}for the individual circles and .dot-joints.x-grid:hover{filter:url(#f)} for the group of lines: *{ box-sizing: border-box; margin: 0; padding: 0; } html, body{ height: 100%; width: 100%; } #import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,500&display=swap'); body { font-family: 'Roboto Mono', monospace; } .graph .labels.x-labels { text-anchor: middle; } .graph .labels.y-labels { text-anchor: end; } .graph { height: 500px; width: 800px; } .graph .grid { stroke: #ccc; stroke-dasharray: 0; stroke-width: 3; } .labels { font-size: 17px; font-weight: 400; } .label-title { font-weight: 500; text-transform: uppercase; font-size: 15px; fill: black; } .data { fill: #f86d36; stroke-width: 1; } .data circle:hover{filter:url(#f)} .graph .dot-joints { stroke: #f86d36; stroke-dasharray: 0; stroke-width: 3; } .dot-joints.x-grid:hover{filter:url(#f)} <svg version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="graph" aria-labelledby="title" role="img"> <defs> <filter id="f" filterUnits="userSpaceOnUse" id="shadow" x="-10" y="-150" width="120%" height="120%"> <feGaussianBlur in="SourceAlpha" stdDeviation="5" result="blur"></feGaussianBlur> <feOffset in="blur" dx="3" dy="1" result="shadow"></feOffset> <feFlood flood-color="rgba(0,0,0,.52)" result="color" /> <feComposite in ="color" in2="shadow" operator="in" /> <feComposite in="SourceGraphic"/> </filter> </defs> <g class="grid x-grid" id="xGrid"> <line x1="90" x2="90" y1="5" y2="371"></line> </g> <g class="grid x-grid" id="xGrid"> <line x1="90" x2="705" y1="370" y2="370"></line> </g> <g class="labels x-labels"><text x="100" y="400">2008</text><text x="246" y="400">2009</text><text x="392" y="400">2010</text><text x="538" y="400">2011</text><text x="694" y="400">2012</text><text x="400" y="440" class="label-title">Year</text></g> <g class="labels x-labels"><text x="70" y="15">15</text><text x="70" y="131">10</text><text x="70" y="248">5</text><text x="70" y="373">0</text><text x="35" y="200" class="label-title">Price</text></g> <g class="data" data-setname="Our first data set"> <circle cx="95" cy="192" data-value="7.2" r="5"></circle> <circle cx="240" cy="141" data-value="8.1" r="5"></circle> <circle cx="388" cy="179" data-value="7.7" r="5"></circle> <circle cx="531" cy="200" data-value="6.8" r="5"></circle> <circle cx="677" cy="104" data-value="6.7" r="5"></circle> </g> <g class="dot-joints x-grid" > <line x1="95" x2="240" y1="192" y2="141"></line> <line x1="240" x2="388" y1="141" y2="179"></line> <line x1="388" x2="531" y1="179" y2="200"></line> <line x1="531" x2="677" y1="200" y2="104"></line> </g> </svg> Alternatively you may want this instead: svg:hover .data, svg:hover .dot-joints.x-grid{filter:url(#f)} When hovering the svg element apply shadow to the lines and circles. *{ box-sizing: border-box; margin: 0; padding: 0; } html, body{ height: 100%; width: 100%; } #import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,500&display=swap'); body { font-family: 'Roboto Mono', monospace; } .graph .labels.x-labels { text-anchor: middle; } .graph .labels.y-labels { text-anchor: end; } .graph { height: 500px; width: 800px; } .graph .grid { stroke: #ccc; stroke-dasharray: 0; stroke-width: 3; } .labels { font-size: 17px; font-weight: 400; } .label-title { font-weight: 500; text-transform: uppercase; font-size: 15px; fill: black; } .data { fill: #f86d36; stroke-width: 1; } .graph .dot-joints { stroke: #f86d36; stroke-dasharray: 0; stroke-width: 3; } svg:hover .data, svg:hover .dot-joints.x-grid{filter:url(#f)} <svg version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="graph" aria-labelledby="title" role="img"> <defs> <filter id="f" filterUnits="userSpaceOnUse" id="shadow" x="-10" y="-150" width="120%" height="120%"> <feGaussianBlur in="SourceAlpha" stdDeviation="5" result="blur"></feGaussianBlur> <feOffset in="blur" dx="3" dy="1" result="shadow"></feOffset> <feFlood flood-color="rgba(0,0,0,.52)" result="color" /> <feComposite in ="color" in2="shadow" operator="in" /> <feComposite in="SourceGraphic"/> </filter> </defs> <g class="grid x-grid" id="xGrid"> <line x1="90" x2="90" y1="5" y2="371"></line> </g> <g class="grid x-grid" id="xGrid"> <line x1="90" x2="705" y1="370" y2="370"></line> </g> <g class="labels x-labels"><text x="100" y="400">2008</text><text x="246" y="400">2009</text><text x="392" y="400">2010</text><text x="538" y="400">2011</text><text x="694" y="400">2012</text><text x="400" y="440" class="label-title">Year</text></g> <g class="labels x-labels"><text x="70" y="15">15</text><text x="70" y="131">10</text><text x="70" y="248">5</text><text x="70" y="373">0</text><text x="35" y="200" class="label-title">Price</text></g> <g class="data" data-setname="Our first data set"> <circle cx="95" cy="192" data-value="7.2" r="5"></circle> <circle cx="240" cy="141" data-value="8.1" r="5"></circle> <circle cx="388" cy="179" data-value="7.7" r="5"></circle> <circle cx="531" cy="200" data-value="6.8" r="5"></circle> <circle cx="677" cy="104" data-value="6.7" r="5"></circle> </g> <g class="dot-joints x-grid" > <line x1="95" x2="240" y1="192" y2="141"></line> <line x1="240" x2="388" y1="141" y2="179"></line> <line x1="388" x2="531" y1="179" y2="200"></line> <line x1="531" x2="677" y1="200" y2="104"></line> </g> </svg> UPDATE The OP is commenting: Can you explain it in a little more details In the <defs> I've added an svg filter. This filter first is creating a blur feGaussianBlur. You may need to change the stdDeviation in order to change the aspect of the shadow. Next is offsetting the the previously created blur feOffset: You may need to change the dx="3"and dy="1" attributes in order to move the shadow. Then feFlood and feComposite are used to add a color to the shadow. In this case I'm using a semitransparent black, but you can use the color you want. I'm using this filter to apply the shadow only to those elements you want: filter:url(#f) - where f is the filter's id
Why can't I add a border on my svg path?
I have a svg where I am highlighting my path on hover. Here is my svg <svg version="1.1" x="0px" y="0px" viewBox="0 0 2986 886" enable-background="new 0 0 2986 886"> <image display="block" overflow="visible" width="2986" height="886" xlink:href="/A-1.jpg"> </image> <path fill="none" stroke="#000000" strokeWidth="0.25" stroke-miterlimit="10" points="2781.5,905 2986,905 2986,865.6 2842.7,634.6 2635.2,601.1 " id="1"></path> .... </svg> Here is my css: svg path{ fill:none; pointer-events:all; } svg path:hover { fill: rgba(73,143,226,0.80); border: 5px solid #31C6FF; } svg rect:hover { fill: rgba(73,143,226,0.80); border: 5px solid #31C6FF; } svg polygon:hover { fill: rgba(73,143,226,0.80); border: 5px solid #31C6FF; } When I hover, my path changes to the proper color, but I don't get a border. What am I misunderstanding?
For SVG, use the stroke property instead of border. Edit: As the owner of the question points out in comments, stroke-opacity: 1 was needed as well as stroke and stroke-width.
rotate svg fill path box
I design box border using svg like this : HTML: <svg class="decor" height="100%" preserveaspectratio="none" version="1.1" viewbox="0 0 100 100" width="100%" xmlns="http://www.w3.org/2000/svg"> <path d="M0 0 L100 100 L0 100" stroke-width="0"></path> </svg> CSS: .decor { fill: #F00; stroke: #e74c3c; } result: Now i need to rotation to this: How do generate this?! DEMO FIDDLE
Add transform="rotate(180, 50, 50)" to the path .decor { fill: #F00; stroke: #e74c3c; } <svg class="decor" height="100%" viewBox="0 0 100 100" width="100%" preserveAspectRatio="none" > <path transform="rotate(180, 50, 50)" d="M0 0 L100 100 L0 100"></path> </svg>
Just do this: .decor { fill: #F00; stroke: #e74c3c; -webkit-transform: rotate(180deg); transform: rotate(180deg); } This will rotate it to be the way you want. Fiddle: http://jsfiddle.net/jkvp1x8m/