Is any idea how it can be done?
Expecting this:
https://codesandbox.io/s/how-to-apply-conic-gradient-to-svg-stroke-cbx37l
The basic idea here is that four rectangles that have there own linear gradient are masked off by a dotted stroke. The gradients overlap overlap each other in the corners so it looks like a continues gradient.
The dotted stroke in mask m1 has rounded line caps and then another mask (m2) is masking off half of the stroke.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 300"
width="500">
<defs>
<linearGradient id="top">
<stop offset="10%" stop-color="DarkViolet"/>
<stop offset="90%" stop-color="DeepSkyBlue"/>
</linearGradient>
<linearGradient id="right" gradientTransform="rotate(90)">
<stop offset="10%" stop-color="DeepSkyBlue"/>
<stop offset="50%" stop-color="Green"/>
<stop offset="90%" stop-color="Yellow"/>
</linearGradient>
<linearGradient id="bottom">
<stop offset="10%" stop-color="Red"/>
<stop offset="50%" stop-color="Orange"/>
<stop offset="90%" stop-color="Yellow"/>
</linearGradient>
<linearGradient id="left" gradientTransform="rotate(90)">
<stop offset="10%" stop-color="DarkViolet"/>
<stop offset="90%" stop-color="Red"/>
</linearGradient>
<mask id="m1">
<rect x="4" y="4" rx="20" width="392" height="292"
mask="url(#m2)" stroke="white" stroke-width="8"
stroke-dasharray="5 5 10 5 7 4" stroke-linecap="round"
pathLength="400" filter="url(#distort)" />
</mask>
<mask id="m2">
<rect x="4" y="4" rx="20" width="392" height="292" fill="white" />
</mask>
</defs>
<g mask="url(#m1)">
<rect width="400" height="20" fill="url(#top)"/>
<rect width="20" height="300" x="380" fill="url(#right)"/>
<rect width="400" height="20" y="280" fill="url(#bottom)"/>
<rect width="20" height="300" fill="url(#left)"/>
</g>
</svg>
I was able to implement it with pattern image.
https://codesandbox.io/s/how-to-apply-conic-gradient-to-svg-stroke-cbx37l
Related
This SVG is displayed correctly on Chrome, but disappear on Mozilla and iOS. Could you please give me some insights about what's wrong with it?
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="450" height="616" viewBox="0 0 450 616" fill="none">
<g filter="url(#filter1_b)" style="
">
<rect x="63.352" y="24.3788" width="376.5" height="544.5" rx="59.25" transform="rotate(5 63.352 24.3788)" stroke="url(#paint1_radial)" stroke-width="3.5" style="
/* display: none; */
"/>
<rect x="63.352" y="24.3788" width="376.5" height="544.5" rx="59.25" transform="rotate(5 63.352 24.3788)" stroke="url(#paint2_radial)" stroke-width="3.5"/>
<rect x="63.352" y="24.3788" width="376.5" height="544.5" rx="59.25" transform="rotate(5 63.352 24.3788)" stroke="url(#paint3_radial)" stroke-width="3.5"/>
</g>
<defs>
<filter id="filter0_b" x="-22.9194" y="-14.4363" width="500.154" height="652.872" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feGaussianBlur in="BackgroundImage" stdDeviation="21"/>
<feComposite in2="SourceAlpha" operator="in" result="effect1_backgroundBlur"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_backgroundBlur" result="shape"/>
</filter>
<filter id="filter1_b" x="-22.9194" y="-14.4363" width="500.154" height="652.872" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feGaussianBlur in="BackgroundImage" stdDeviation="21"/>
<feComposite in2="SourceAlpha" operator="in" result="effect1_backgroundBlur"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_backgroundBlur" result="shape"/>
</filter>
<pattern id="pattern0" patternContentUnits="objectBoundingBox" width="1.31579" height="1.31387">
<use xlink:href="#image0" transform="scale(0.00263158 0.00182482)"/>
</pattern>
<linearGradient id="paint0_linear" x1="73.1612" y1="38.0857" x2="463.816" y2="606.864" gradientUnits="userSpaceOnUse">
<stop stop-color="white" stop-opacity="0.4"/>
<stop offset="1" stop-color="white" stop-opacity="0"/>
</linearGradient>
<radialGradient id="paint1_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(114.681 86.3485) rotate(55.7067) scale(886.206 408.172)">
<stop stop-color="white"/>
<stop offset="1" stop-color="white" stop-opacity="0"/>
</radialGradient>
<radialGradient id="paint2_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(251.761 296.483) rotate(58.5326) scale(410.938 284.945)">
<stop stop-color="#48E6D8"/>
<stop offset="1" stop-color="#48E6D8" stop-opacity="0"/>
</radialGradient>
<radialGradient id="paint3_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(414.269 42.5193) rotate(124.907) scale(676.798 469.762)">
<stop stop-color="#002421"/>
<stop offset="0.635417" stop-color="#002421" stop-opacity="0.364583"/>
<stop offset="1" stop-color="#002421" stop-opacity="0"/>
</radialGradient>
</defs>
</svg>
Sample here: https://codepen.io/burianovata_i/pen/WNoeaLd
As #RobertLongson commented, Firefox does not support BackgroundImage pseudo inputs. So I removed that lines and it worked!
I want to fill svg with radial gradient but unfortunately it doesn't work. What kind of mistake I have done?
<body>
<svg style="display:none">
<defs>
<radialGradient id="RadialGradient1">
<stop offset="0%" stop-color="red"/>
<stop offset="100%" stop-color="blue"/>
</radialGradient>
<radialGradient id="RadialGradient2" cx="0.25" cy="0.25" r="0.25">
<stop offset="0%" stop-color="red"/>
<stop offset="100%" stop-color="blue"/>
</radialGradient>
</defs>
<symbol viewBox="0 0 200 200" id="img--svg--icon">
<path d="M 100, 100
m -75, 0
a 75,75 0 1,0 150,0
a 75,75 0 1,0 -150,0"/>
</symbol>
</svg>
<section class="item item--two">
<svg width="47" height="21" class="item__icon" fill="url(#RadialGradient1)">
<use xlink:href="#img--svg--icon"></use>
</svg>
<p class="item__descr">Гипогликемия</p>
</section>
You can use width and height set to 0, instead of display: none.
Display: none will be otherwise transferred to your target svg.
<svg width="0" height="0">
<defs>
... your gradients here
</defs>
</svg>
<section class="item item--two">
<svg width="47" height="21" class="item__icon" fill="url(#RadialGradient1)">
<use xlink:href="#img--svg--icon"></use>
</svg>
<p class="item__descr">Гипогликемия</p>
</section>
The following file is a work in progress showing 3 lamps, I am trying to show text centered both horizontally and vertically in each lamp. I'm not sure whats happening but only the text for lamp3 is appearing and it is not in the correct location. The other lamps do no show the text at all.
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" id="root">
<defs>
<linearGradient y2="0" id="lamp2rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf"/>
<stop offset="1" stop-color="#404040"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp2cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00"/>
<stop offset="1" stop-opacity="0.988281" stop-color="#018201"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp2spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff"/>
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306"/>
</linearGradient>
<linearGradient y2="0" id="lamp3rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf"/>
<stop offset="1" stop-color="#404040"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp3cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00"/>
<stop offset="1" stop-opacity="0.988281" stop-color="#018201"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp3spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff"/>
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306"/>
</linearGradient>
<linearGradient y2="0" id="lamp1rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf"/>
<stop offset="1" stop-color="#404040"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp1cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00"/>
<stop offset="1" stop-opacity="0.988281" stop-color="#018201"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp1spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff"/>
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306"/>
</linearGradient>
</defs>
<g id="lamp2" transform="translate(15.0,0.0) scale(0.25)">
<title>Lamp 2</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp2svg_3" cy="240" stroke-width="17.5"/>
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp2rim)" r="160" cx="319.252837" id="lamp2svg_7" cy="239.999045" stroke-width="17.5"/>
<circle stroke-linecap="round" fill="url(#lamp2cap)" r="150" cx="320.000535" id="lamp2svg_8" cy="240.001698" stroke-width="17.5"/>
<text text-anchor="middle" x="0" y="0" font-size="55" font-family="Verdana" fill="blue">CCC</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp2spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5"/>
</g>
<g id="lamp3" transform="translate(100.0,82.0) scale(0.25)">
<title>Lamp 3</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp3svg_3" cy="240" stroke-width="17.5"/>
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp3rim)" r="160" cx="319.252837" id="lamp3svg_7" cy="239.999045" stroke-width="17.5"/>
<circle stroke-linecap="round" fill="url(#lamp3cap)" r="150" cx="320.000535" id="lamp3svg_8" cy="240.001698" stroke-width="17.5"/>
<text text-anchor="middle" x="0" y="0" font-size="55" font-family="Verdana" fill="blue">EEE</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp3spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5"/>
</g>
<g id="lamp1" transform="translate(100.0,0.0) scale(0.25)">
<title>Lamp 1</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp1svg_3" cy="240" stroke-width="17.5"/>
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp1rim)" r="160" cx="319.252837" id="lamp1svg_7" cy="239.999045" stroke-width="17.5"/>
<circle stroke-linecap="round" fill="url(#lamp1cap)" r="150" cx="320.000535" id="lamp1svg_8" cy="240.001698" stroke-width="17.5"/>
<text text-anchor="middle" x="0" y="0" font-size="55" font-family="Verdana" fill="blue">AAA</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp1spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5"/>
</g>
</svg>
I really would like an elegant way of centering the text in the parent group.
JSFiddle: https://jsfiddle.net/8kouys3w/6/
clean up code
Main problem: all shapes are stacked on top of each other
other problem (fixed):
transform="translate(1154.0,0.0) scale(0.25)">There really si no reason to transfrom it that far. And scaling should also not be nesasary since you are doing it on all elements.
Your svg does not have a viewBox. This means it will not scale.
Text: The text displayed was at 0.0 (origin) not any where close to the shapes.
Other (not fixed):
WHY WOULD YOU EVER ROTATE A CIRCLE?
circle transform="rotate(90 320 240)"
Your linear gradients have a stop opacity of 0.988281 Thats a lot of decimals for a opacity really close to 1.
Im going to take a wild gues here and say your code is generated and not coded. So if your having problems with generated code you should fix those issues inside your editor, or learn the basics of svg like viewBox and the text element atleast. That would take less time then posting and answer here.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 110" id="root">
<defs>
<linearGradient y2="0" id="lamp2rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf" />
<stop offset="1" stop-color="#404040" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp2cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00" />
<stop offset="1" stop-opacity="0.988281" stop-color="#018201" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp2spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff" />
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306" />
</linearGradient>
<linearGradient y2="0" id="lamp3rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf" />
<stop offset="1" stop-color="#404040" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp3cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00" />
<stop offset="1" stop-opacity="0.988281" stop-color="#018201" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp3spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff" />
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306" />
</linearGradient>
<linearGradient y2="0" id="lamp1rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf" />
<stop offset="1" stop-color="#404040" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp1cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00" />
<stop offset="1" stop-opacity="0.988281" stop-color="#018201" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp1spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff" />
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306" />
</linearGradient>
</defs>
<g id="lamp2" transform="scale(0.25)">
<title>Lamp 2</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp2svg_3" cy="240" stroke-width="17.5" />
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp2rim)" r="160" cx="319.252837" id="lamp2svg_7" cy="239.999045" stroke-width="17.5" />
<circle stroke-linecap="round" fill="url(#lamp2cap)" r="150" cx="320.000535" id="lamp2svg_8" cy="240.001698" stroke-width="17.5" />
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp2spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5" />
<text x="250" y="260" font-size="55" font-family="Verdana" fill="blue">CCC</text>
</g>
<g id="lamp3" transform="translate(100,0) scale(0.25)">
<title>Lamp 3</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp3svg_3" cy="240" stroke-width="17.5" />
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp3rim)" r="160" cx="319.252837" id="lamp3svg_7" cy="239.999045" stroke-width="17.5" />
<circle stroke-linecap="round" fill="url(#lamp3cap)" r="150" cx="320.000535" id="lamp3svg_8" cy="240.001698" stroke-width="17.5" />
<text x="250" y="260" font-size="55" font-family="Verdana" fill="blue">EEE</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp3spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5" />
</g>
<g id="lamp1" transform="translate(200,0) scale(0.25)">
<title>Lamp 1</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp1svg_3" cy="240" stroke-width="17.5" />
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp1rim)" r="160" cx="319.252837" id="lamp1svg_7" cy="239.999045" stroke-width="17.5" />
<circle stroke-linecap="round" fill="url(#lamp1cap)" r="150" cx="320.000535" id="lamp1svg_8" cy="240.001698" stroke-width="17.5" />
<text x="250" y="260" font-size="55" font-family="Verdana" fill="blue">AAA</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp1spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5" />
</g>
</svg>
This works...viewBox isn't required.
<svg xmlns="http://www.w3.org/2000/svg" id="root">
<defs>
<linearGradient y2="0" id="lamp2rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf" />
<stop offset="1" stop-color="#404040" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp2cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00" />
<stop offset="1" stop-opacity="0.988281" stop-color="#018201" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp2spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff" />
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306" />
</linearGradient>
<linearGradient y2="0" id="lamp3rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf" />
<stop offset="1" stop-color="#404040" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp3cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00" />
<stop offset="1" stop-opacity="0.988281" stop-color="#018201" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp3spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff" />
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306" />
</linearGradient>
<linearGradient y2="0" id="lamp1rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf" />
<stop offset="1" stop-color="#404040" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp1cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00" />
<stop offset="1" stop-opacity="0.988281" stop-color="#018201" />
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp1spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff" />
<stop offset="0.703125" stop-opacity="0.984375" stop- color="#06d306" />
</linearGradient>
</defs>
<g id="lamp1" transform="translate(100,0) scale(0.25)">
<title>Lamp 1</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp1svg_3" cy="240" stroke-width="17.5" />
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp1rim)" r="160" cx="319.252837" id="lamp1svg_7" cy="239.999045" stroke-width="17.5" />
<circle stroke-linecap="round" fill="url(#lamp1cap)" r="150" cx="320.000535" id="lamp1svg_8" cy="240.001698" stroke-width="17.5" />
<text x="250" y="260" font-size="55" font-family="Verdana" fill="blue">AAA</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp1spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5" />
</g>
<g id="lamp2" transform="translate(200,0) scale(0.25)">
<title>Lamp 2</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp2svg_3" cy="240" stroke-width="17.5" />
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp2rim)" r="160" cx="319.252837" id="lamp2svg_7" cy="239.999045" stroke-width="17.5" />
<circle stroke-linecap="round" fill="url(#lamp2cap)" r="150" cx="320.000535" id="lamp2svg_8" cy="240.001698" stroke-width="17.5" />
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp2spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5" />
<text x="250" y="260" font-size="55" font-family="Verdana" fill="blue">BBB</text>
</g>
<g id="lamp3" transform="translate(200,100) scale(0.25)">
<title>Lamp 3</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp3svg_3" cy="240" stroke-width="17.5" />
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp3rim)" r="160" cx="319.252837" id="lamp3svg_7" cy="239.999045" stroke-width="17.5" />
<circle stroke-linecap="round" fill="url(#lamp3cap)" r="150" cx="320.000535" id="lamp3svg_8" cy="240.001698" stroke-width="17.5" />
<text x="250" y="260" font-size="55" font-family="Verdana" fill="blue">CCC</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp3spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5" />
</g>
</svg>
To recap...there wasn't anything wrong with the original SVG, all that has been done was to change the values for x and y to 250 and 260.
JSFiddle: https://jsfiddle.net/8kouys3w/12/
I am new here and may have some questions which can be too simple.
Recently I have to learn svg ,and I found something puzzled.
This one
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100px" height="100px">
<defs>
<radialGradient id="Gradient5" cx="0.5" cy="0.5" r="0.5" fx="0.13" fy="0.13">
<stop offset="0%" stop-color="red"/>
<stop offset="100%" stop-color="blue"/>
</radialGradient>
</defs>
<rect x="10" y="10" rx="15" ry="15" width="100" height="100" fill="url(#Gradient5)" stroke="black" stroke-width="2"/>
</svg>
What happen to top left corner ?
I am weak in Math and I am aware that this is a mathmatical problem.May anyone help me?
You have mapped the 0% of the gradientStop (your fx/fy) to a point outside the radius of the gradient (your cx/cy), and it's not displaying. Note that when you change your fx/fy to just inside the gradient area, it displays just fine. (This is a Chrome bug - if the focal point is specified outside the gradient area, it's supposed to be set at the closest point on the area's perimeter. This is correctly handled in IE and Firefox. I guess I'm filing a bug on this.)
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100px" height="100px">
<defs>
<radialGradient id="Gradient5" cx="0.5" cy="0.5" r="0.5" fx="0.15" fy="0.15">
<stop offset="0%" stop-color="red"/>
<stop offset="100%" stop-color="blue"/>
</radialGradient>
</defs>
<rect x="10" y="10" rx="15" ry="15" width="100" height="100" fill="url(#Gradient5)" stroke="black" stroke-width="2"/>
</svg>
Try this -
I changed both fx and fy to 50%
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100px" height="100px">
<defs>
<radialGradient id="Gradient5" cx="0.5" cy="0.5" r="0.5" fx="50%" fy="50%">
<stop offset="0%" stop-color="red"/>
<stop offset="100%" stop-color="blue"/>
</radialGradient>
</defs>
<rect x="10" y="10" rx="15" ry="15" width="100" height="100" fill="url(#Gradient5)" stroke="black" stroke-width="2"/>
</svg>
I have a jsfiddle here - http://jsfiddle.net/apbuc773/
I'd like to create a star using svg.
I'd like to stroke the outside of the star. In my example the stroke is on every line which dissects the inner shape.
Also is it possible to half fill the star shape.
I'd like to use this for a star rating but I need half and maybe quarter fills.
<svg height="210" width="500">
<polygon points="100,10 40,198 190,78 10,78 160,198" style="fill:red;stroke:blue;"/>
</svg>
You can alternatively do this with a filter. Here is one that animates the fill:
<svg height="210" width="500">
<defs>
<filter id="fillpartial" primitiveUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
<feFlood x="0%" y="0%" width="100%" height="100%" flood-color="red" />
<feOffset dy="0.5">
<animate attributeName="dy" from="1" to=".5" dur="3s" />
</feOffset>
<feComposite operator="in" in2="SourceGraphic" />
<feComposite operator="over" in2="SourceGraphic" />
</filter>
</defs>
<polygon filter="url(#fillpartial)" points="165.000, 185.000, 188.511, 197.361, 184.021, 171.180,
203.042, 152.639,
176.756, 148.820,
165.000, 125.000,
153.244, 148.820,
126.958, 152.639,
145.979, 171.180,
141.489, 197.361,
165.000, 185.000" style="fill:white;stroke:red;" />
</svg>
Here is a example: http://jsfiddle.net/apbuc773/11/
Gradient can be used like this:
<svg height="210" width="500">
<defs>
<linearGradient id="half">
<stop offset="0%" stop-color="red" />
<stop offset="50%" stop-color="red" />
<stop offset="50%" stop-color="white" />
<stop offset="100%" stop-color="white" />
</linearGradient>
</defs>
<g fill="url(#half)" stroke="blue" stroke-width="2">
If you don't want to change your polygon points, just apply this polygon twice: one time with stroke and one time without.
I've noticed the comment of the accepted answer, and here is how you fill an custom shape:
<svg width="100" height="100" viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<clipPath id="heart">
<path d="M81.495,13.923c-11.368-5.261-26.234-0.311-31.489,11.032C44.74,13.612,29.879,8.657,18.511,13.923 C6.402,19.539,0.613,33.883,10.175,50.804c6.792,12.04,18.826,21.111,39.831,37.379c20.993-16.268,33.033-25.344,39.819-37.379 C99.387,33.883,93.598,19.539,81.495,13.923z"/>
</clipPath>
</defs>
<rect x="0" y="0" fill="rgb(217,217,217)" width="100%" height="100%" clip-path="url(#heart)" />
<rect x="0" y="50%" fill="red" width="100%" height="100%" clip-path="url(#heart)" />
</svg>