Im using react, Trying to convert an SVG to jsx and all seems pretty well however all of my svgs have an enable-background property
style="enable-background:new 0 0 473.806 473.806;"
Which im having trouble converting to JSX
Im currently using
style={{enableBackground:'new 0 0 387.2 387.2'}}
Which doesnt work, I would just use an img tag however i want to change the color of the SVG on hover.
Update: heres the SVG
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="35px" height="35px" viewBox="0 0 35 35" style="enable-background:new 0 0 35 35;" xml:space="preserve">
<g>
<path d="M25.302,0H9.698c-1.3,0-2.364,1.063-2.364,2.364v30.271C7.334,33.936,8.398,35,9.698,35h15.604
c1.3,0,2.364-1.062,2.364-2.364V2.364C27.666,1.063,26.602,0,25.302,0z M15.004,1.704h4.992c0.158,0,0.286,0.128,0.286,0.287
c0,0.158-0.128,0.286-0.286,0.286h-4.992c-0.158,0-0.286-0.128-0.286-0.286C14.718,1.832,14.846,1.704,15.004,1.704z M17.5,33.818
c-0.653,0-1.182-0.529-1.182-1.183s0.529-1.182,1.182-1.182s1.182,0.528,1.182,1.182S18.153,33.818,17.5,33.818z M26.021,30.625
H8.979V3.749h17.042V30.625z"/>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>
Removing the style="enable-background..." works fine. See below.
If yours fails, then you are doing something else wrong somewhere.
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="35px" height="35px" viewBox="0 0 35 35" xml:space="preserve">
<g>
<path d="M25.302,0H9.698c-1.3,0-2.364,1.063-2.364,2.364v30.271C7.334,33.936,8.398,35,9.698,35h15.604
c1.3,0,2.364-1.062,2.364-2.364V2.364C27.666,1.063,26.602,0,25.302,0z M15.004,1.704h4.992c0.158,0,0.286,0.128,0.286,0.287
c0,0.158-0.128,0.286-0.286,0.286h-4.992c-0.158,0-0.286-0.128-0.286-0.286C14.718,1.832,14.846,1.704,15.004,1.704z M17.5,33.818
c-0.653,0-1.182-0.529-1.182-1.183s0.529-1.182,1.182-1.182s1.182,0.528,1.182,1.182S18.153,33.818,17.5,33.818z M26.021,30.625
H8.979V3.749h17.042V30.625z"/>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>
hi i have svg path where i am placing an image https://i.imgur.com/NFhr6hq.jpg from . when i place its just display in center of path and not filling others area as following my desired image https://i.imgur.com/tdjZpKh.jpg
how i can place image on wall as tiles ?
<defs>
<pattern id="img1" patternUnits="userSpaceOnUse" width="100" height="100">
<image x="0" y="0" xlink:href="stile.jpg" width="100" height="100" />
</pattern>
</defs>
<path d="M 752 180 v 192 h 215 V 145 L 752 180 Z M 916 358 l -130 0.246 v -78.369 L 916 270 V 358 Z"/>
</path>
<script>
jQuery(function($){
$('path').click(function(){
this.style.fill = "url(#img1)";
alert(this.id);
});
});
</script>
when i click on path with jquery am applying image on it
The problem is that your image has white borders. If you want to use that image you need to put the image inside a symbol with a viewBox that is cropping the white border of the image like so:
<svg width="100%" height="100%" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
<defs>
<symbol id="s" viewBox="2.5 2.5 38 35">
<image x="0" y="0" xlink:href="https://i.imgur.com/NFhr6hq.jpg" width="48" height="45" />
</symbol>
<pattern id="img1" patternUnits="userSpaceOnUse" width="30" height="30">
<use xlink:href="#s" width="30" height="30" />
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#img1)" />
</svg>
Alternatively you may use a different image with no white borders and in this case you may use the #Alexandr_TT's solution.
UPDATE:
The OP is commenting:
i have updatted question, there i have no rect but path . when i click on path , jquery update path fill area with image
In this case instead of filling the rect you fill the path like so:
<svg viewBox="750 145 230 230" xmlns="http://www.w3.org/2000/svg">
<defs>
<symbol id="s" viewBox="3.1 2.5 38 35">
<image x="0" y="0" xlink:href="https://i.imgur.com/NFhr6hq.jpg" width="48" height="45" />
</symbol>
<pattern id="img1" patternUnits="userSpaceOnUse" width="38" height="35">
<use xlink:href="#s" width="38" height="35" />
</pattern>
</defs>
<!--<rect width="100%" height="100%" fill="url(#img1)" />-->
<path d="M 752 180 v 192 h 215 V 145 L 752 180 Z M 916 358 l -130 0.246 v -78.369 L 916 270 V 358 Z" fill="url(#img1)"/>
</svg>
Pattern filling any shape
<rect width="100%" height="100%" fill="url(#img1)" />
<svg width="100%" height="100%" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
<defs>
<pattern id="img1" patternUnits="userSpaceOnUse" width="100" height="100">
<image x="0" y="0" xlink:href="https://i.imgur.com/NFhr6hq.jpg" width="100px" height="100px" />
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#img1)" />
</svg>
Update
Tile Fill Path
<svg width="100%" height="100%" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg">
<defs>
<pattern id="img1" patternUnits="userSpaceOnUse" width="25" height="25">
<image x="0" y="0" xlink:href="https://i.imgur.com/NFhr6hq.jpg" width="25px" height="25px" />
</pattern>
</defs>
<path stroke="gray" fill="url(#img1)" transform="translate(-700 -100)" d="M 752 180 v 192 h 215 V 145 L 752 180 Z M 916 358 l -130 0.246 v -78.369 L 916 270 V 358 Z" />
</svg>
Can anyone help me identify why my text is not rendering in the defined path #textPath03 ? The path is rendered as supposed, but when I put it inside a <defs> and try to use it, it doesn`t work.
<svg version="1.1" height="700" width="700" viewBox="-5 -5 110 110" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" data-reactid="13">
<defs data-reactid="14">
<path id="#textPath03" d="M95,50 A45,45 0 0 0 50,5" data-reactid="15"></path>
</defs>
<line x1="50" y1="50" x2="100" y2="50" stroke="black" data-reactid="16"></line>
<line x1="50" y1="50" x2="50" y2="0" stroke="black" data-reactid="17"></line>
<path d="M90,50 A40,40 0 0 0 50,10" fill="none" stroke="green" data-reactid="18"></path>
<use xlink:href="#textPath03" fill="none" stroke="red" data-reactid="19"></use>
<text x="2" y="40%" font-size="20" data-reactid="20">
<textPath xlink:href="#textPath03" data-reactid="21">Teste</textPath>
</text>
</svg>
This is a REACT rendered SVG.
Thanks!!
The path id contains an extraneous # character. Only the reference to the path should have that. Removing it fixes your example...
<svg version="1.1" height="700" width="700" viewBox="-5 -5 110 110" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" data-reactid="13">
<defs data-reactid="14">
<path id="textPath03" d="M95,50 A45,45 0 0 0 50,5" data-reactid="15"></path>
</defs>
<line x1="50" y1="50" x2="100" y2="50" stroke="black" data-reactid="16"></line>
<line x1="50" y1="50" x2="50" y2="0" stroke="black" data-reactid="17"></line>
<path d="M90,50 A40,40 0 0 0 50,10" fill="none" stroke="green" data-reactid="18"></path>
<use xlink:href="#textPath03" fill="none" stroke="red" data-reactid="19"></use>
<text x="2" y="40%" font-size="20" data-reactid="20">
<textPath xlink:href="#textPath03" data-reactid="21">Teste</textPath>
</text>
</svg>
I'm trying to use the react-native-svg library particularly with the Symbol element as follows. I used the example code here:
<Svg
height="150"
width="110"
>
<Symbol id="symbol" viewbox="0 0 150 110" width="100" height="50">
<Circle cx="50" cy="50" r="40" strokeWidth="8" stroke="red" fill="red"/>
<Circle cx="90" cy="60" r="40" strokeWidth="8" stroke="green" fill="white"/>
</Symbol>
<Use
href="#symbol"
x="0"
y="0"
/>
When I run this code, I get the following error in the logs and the app crashes:
<Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: nil argument'
When I don't use the Symbol object everything works fine. Has anyone run into this issue before?
I was actually able to fix this by copying and pasting the example on this page:
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol
You need the width and height elements on the Use tag as follows:
<Svg height="150" width="110">
<Symbol id="symbol" viewbox="0 0 150 110" width="100" height="50">
<Circle cx="50" cy="50" r="40" strokeWidth="8" stroke="red" fill="red"/>
<Circle cx="90" cy="60" r="40" strokeWidth="8" stroke="green" fill="white"/>
</Symbol>
<Use href="#symbol" x="0" y="0" width="100" height="50"/>
</Svg>
I definitely thought I tried that before, so it may have also been me running the following clear cache and re-compiling commands as well:
rm -rf node_modules && npm install and npm start -- --reset-cache
Either way, problem fixed!
I've got a problem with an SVG image.
The following code works in all browser but not in safari mobile.
(I use IOS Simulator).
Do you know why? I've not find a solution because all other images I've seen works with the same syntax.
<svg version="1.1" id="logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="150px" height="125px" viewBox="0 0 150 125" enable-background="new 0 0 150 125" xml:space="preserve">
<path fill="none" stroke="#E26161" d="M1.295,1"/>
<path fill="none" stroke="#E26161" d="M1.295,125"/>
<path fill="none" stroke="#000000" d="M-9.681-16.75"/>
<path fill="none" stroke="#000000" d="M93.751,21.722"/>
<path fill="none" stroke="#000000" d="M151.887,123.541"/>
<path fill="none" stroke="#000000" d="M77.072,62.437"/>
<path fill="none" stroke="#000000" d="M2.328,1.391"/>
<path fill="none" stroke="#E26161" d="M77.072,62.437"/>
<path fill="none" stroke="#E26161" d="M1.295,0.667"/>
<line fill="none" stroke="#E26161" x1="149.043" y1="125" x2="149.043" y2="0"/>
<line fill="none" stroke="#E26161" x1="75.022" y1="62.5" x2="149.043" y2="0"/>
<line fill="none" stroke="#111111" x1="1" y1="124.938" x2="75.022" y2="62.437"/>
<line fill="none" stroke="#E26161" x1="1" y1="0" x2="75.28" y2="62.906"/>
<line fill="none" stroke="#E26161" x1="1" y1="125" x2="1" y2="0"/>
</svg>
It looks like you have an invisible U+200B character at the end of your closing </svg>. Remove it and it should work.